Ich habe einen WCF-Dienst erstellt, der auf einem Server von einem Windows-Dienst gehostet wird. Alles funktioniert gut und ich habe bereits eine Methode getestet. Jetzt muß ich wie dieser einen Httprequest von meinem Client senden:Fehler 400: ungültige Anforderung auf httpwebrequest
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(String.Format(@"http://192.168.0.170:9001/myServ/Start/{0}/{1}", "blabla", "blabla"));
req.Method = "GET";
Das Problem ist, dass ich eine Ausnahme auf Client-Seite erhalte die besagt, dass meine Anfrage ungültig ist. Ich kann nicht verstehen warum.
Das ist mein Wcf-Dienst:
[OperationContract]
[WebInvoke(Method = "GET",
UriTemplate = "Start/{param1}/{param2}")]
string Mod(string param1, string param2);
Hier ist meine Konfiguration
<?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>
Sie könnten auch das Anfrageformat übergeben. versuchen Sie dies [WCF parametrisierte Post Call] (https://stackoverflow.com/questions/25830289/how-to-pass-parameters-to-a-wcf-post-method-a-restful-services) –
Ich habe bereits a Post ohne das Anfrageformat anzugeben, und es hat funktioniert. Ich frage mich, warum dieses einfache GET nicht wie vorgesehen funktioniert. Mein Problem ist, dass ich nicht einmal den Dienst im Debug erreichen kann. Ich bekomme diese Ausnahme auf Client-Seite –
Könnten Sie bitte die Konfiguration für uns veröffentlichen? Hier ist eine simle GET Anfrage Beispiel http://www.c-sharpcorner.com/UploadFile/0c1bb2/creating-wcf-rest-service/ - falls Sie nicht auf dieser Seite waren. –