远程服务器返回错误:400 Bad Request (WCF)

问题描述 投票:0回答:0

我正在使用 WCF 和 wsDualBinding、WebHttpBinding。 我希望我的服务器向客户端发送 wsdual 请求,然后客户端处理请求并将 json 发送回服务器。

<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);
在这一行我得到了错误。

我已经尝试在我的程序中调用

ServerToClient
而不是我的 ChatService。它正在工作。 但我不明白为什么。

c# wcf webhttpbinding wsdualhttpbinding
© www.soinside.com 2019 - 2024. All rights reserved.