我遇到了这个问题,我查看了所有的网页并看到了很多答案,但没有任何帮助 我的问题是,每次我从wcf服务获得它的400个错误请求 但是当我运行wcf测试客户端时它工作正常
我正在使用vs 2015 我的配置文件(自动生成vs)
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>
<appSettings>
<add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
</appSettings>
<system.web>
<compilation debug="true" />
</system.web>
<!-- When deploying the service library project, the content of the config file must be added to the host's
app.config file. System.Configuration does not support config files for libraries. -->
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IProductService" />
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost:8733/Design_Time_Addresses/Test/Service1/"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IProductService"
contract="ServiceReference.IProductService" name="BasicHttpBinding_IProductService" />
</client>
<services>
<service name="Test.ProductService">
<endpoint address="" binding="basicHttpBinding" contract="Test.IProductService">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="http://localhost:8733/Design_Time_Addresses/Test/Service1/" />
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior>
<!-- To avoid disclosing metadata information,
set the values below to false before deployment -->
<serviceMetadata httpGetEnabled="True" httpsGetEnabled="True" />
<!-- To receive exception details in faults for debugging purposes,
set the value below to true. Set to false before deployment
to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="False" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
<connectionStrings>
<add name="modelEntities" connectionString="metadata=res://*/Products.csdl|res://*/Products.ssdl|res://*/Products.msl;provider=System.Data.SqlClient;provider connection string="data source=localhost;initial catalog=test;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
</connectionStrings>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
</providers>
</entityFramework>
</configuration>
,服务是
public interface IProductService
{
[OperationContract]
[WebInvoke(Method = "GET", ResponseFormat = WebMessageFormat.Json,UriTemplate = "/GetProducts")]
List<Product> GetProducts();
}
这就是补充方法
public List<Product> GetProducts()
{
modelEntities context = new modelEntities();
var productEntity = (from p in context.productEntities select p);
List<Product> products = new List<Product>();
foreach (var item in productEntity)
{
products.Add(TranslateProductEntityToProduct(item));
}
return products;
}
我在没有webinvoke的情况下尝试 也试过webget 并尝试用web绑定替换basichttpbinding 并且在这里和网上寻找许多答案,没有任何帮助我
希望你帮助我由于