[英]Error 400 : invalid request on httpwebrequest
I've built a WCF service that is hosted on a server by a windows service. 我已经构建了Windows服务托管在服务器上的WCF服务。 Everything works fine and i have already tested some method.
一切正常,我已经测试了一些方法。 Now i need to send an httprequest from my client like this one:
现在,我需要像这样从客户端发送一个httprequest:
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(String.Format(@"http://192.168.0.170:9001/myServ/Start/{0}/{1}", "blabla", "blabla"));
req.Method = "GET";
The problem is that i keep getting an exception on client side stating that my request is invalid. 问题是我一直在客户端收到异常消息,说明我的请求无效。 I can't understand why.
我不明白为什么。
This is my wcf service: 这是我的wcf服务:
[OperationContract]
[WebInvoke(Method = "GET",
UriTemplate = "Start/{param1}/{param2}")]
string Mod(string param1, string param2);
Here is my configuration 这是我的配置
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<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>
<webHttpBinding>
<binding maxBufferSize="2147483647"
maxBufferPoolSize="2147483647"
maxReceivedMessageSize="2147483647"
transferMode="Streamed"
sendTimeout="00:05:00"
name="WebHttpBinding_InotifyImp">
<readerQuotas maxDepth="2147483647"
maxStringContentLength="2147483647"
maxArrayLength="2147483647"
maxBytesPerRead="2147483647"
maxNameTableCharCount="2147483647"/>
<security mode="None" />
</binding>
</webHttpBinding>
</bindings>
<services>
<service name="wcfImp.notifyImp" behaviorConfiguration="NewBehavior">
<endpoint address="" behaviorConfiguration="DefaultEndPointBehavior" bindingConfiguration="WebHttpBinding_InotifyImp" binding="webHttpBinding" contract="wcfImp.InotifyImp">
<identity>
<dns value="localhost"/>
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
<host>
<baseAddresses>
<add baseAddress="http://localhost:9001/notifyImp"/>
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="NewBehavior">
<!-- 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="True"/>
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="DefaultEndPointBehavior">
<webHttp helpEnabled="true" />
</behavior>
</endpointBehaviors>
</behaviors>
</system.serviceModel>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1"/>
</startup>
</configuration>
I found the problem. 我发现了问题。 I was hosting my WCF service in debug mode using visual studio 2015 to check the various step of my process.
我使用Visual Studio 2015以调试模式托管WCF服务,以检查过程的各个步骤。 I don't know why, but while i didn't have any problem with the other method, the handler associated to the get method, have an assembly that couldn't be loaded.
我不知道为什么,但是尽管我对其他方法没有任何问题,但与get方法相关联的处理程序具有无法加载的程序集。 I tried to host the service on windows service and everything worked fine
我试图将服务托管在Windows服务上,并且一切正常
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.