The remote server returned an error: 400 Bad Request (WCF)

44 Views Asked by At

I am using WCF and wsDualBinding, WebHttpBinding. I want my server to send a wsdual request to the client, which then processes the request and sends a json back to the server.

<system.serviceModel>
        
        <services>
            <service
              name="ChatTest"
              behaviorConfiguration = "ChatMEXBehavior">
                <endpoint address ="http://localhost:8080/ChatService"
                binding="wsDualHttpBinding"
                contract="Server.IChatService"/>
                
                <endpoint address="http://localhost:8080/JSON"
              binding="webHttpBinding"
              bindingConfiguration="webBindingService"
              contract=Server.IWebService"
              behaviorConfiguration="web"/>
            </service>
        </services>
        <bindings>
            <webHttpBinding>
                <binding name="webBindingService" maxReceivedMessageSize="4194304">
                    <security mode="None"/>
                </binding>
            </webHttpBinding>
        </bindings>
        
        <behaviors>
            <serviceBehaviors>
                <behavior name="ChatMEXBehavior" >
                    <serviceMetadata httpGetEnabled="true" />
                </behavior>
            </serviceBehaviors>
            <endpointBehaviors>
                <behavior name="web">
                    <webHttp/>
                </behavior>
            </endpointBehaviors>
        </behaviors>
    </system.serviceModel>
(ChatClient)
public void ServerToClient(string txt)
        {
            var json = JsonConvert.SerializeObject(txt);
            var content = new StringContent(json, Encoding.UTF8, "application/json");
            var request = new HttpRequestMessage(HttpMethod.Post, webEndpoint);
            request.Content = content;
            webService.SendJSON(request.Content.ReadAsStringAsync().Result);
        }
(ChatService)
public void SendMessage(string message, String clientID)
        {

            if (callback != null && clients.ContainsKey(clientID))
            {
                clients[clientID].ServerToClient("132413414");
            }
        }

webService.SendJSON(request.Content.ReadAsStringAsync().Result); At this line I get the error.

I have tried in my program to call ServerToClient instead of my ChatService. And it's working. But I don't get why.

0

There are 0 best solutions below