System.Net.WebException:远程服务器返回错误:(400)错误请求

时间:2013-09-19 06:19:37

标签: web-services sms bad-request

我正在尝试从我的网络应用程序发送短信。我正在使用推送消息的第三方Web服务。在开发环境中,我可以发送短信,当生产中托管的同一个应用程序收到以下错误时:

System.Net.WebException: The remote server returned an error: (400) Bad Request.
   at System.Net.HttpWebRequest.GetRequestStream(TransportContext& context)
   at System.Net.HttpWebRequest.GetRequestStream()
   at System.ServiceModel.Channels.HttpOutput.WebRequestHttpOutput.GetOutputStream()
   --- End of inner exception stack trace 
Server stack trace: 
   at System.ServiceModel.Channels.HttpOutput.WebRequestHttpOutput.GetOutputStream()
   at System.ServiceModel.Channels.HttpOutput.Send(TimeSpan timeout)
   at System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelRequest.SendRequest(Message message, TimeSpan timeout)
   at System.ServiceModel.Channels.RequestChannel.Request(Message message, TimeSpan timeout)
   at System.ServiceModel.Dispatcher.RequestChannelBinder.Request(Message message, TimeSpan timeout)
   at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
   at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
   at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)
  

以下是我在web.config中所做的更改:

     <system.net>
        <defaultProxy useDefaultCredentials="true" />
      </system.net>
<basicHttpBinding>
    <binding name="IBulkSMS" closeTimeout="00:10:00" openTimeout="00:10:00"
     receiveTimeout="00:10:00" sendTimeout="00:10:00" allowCookies="false"
     bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
     maxBufferSize="500000" maxBufferPoolSize="524288" maxReceivedMessageSize="500000"
     messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
     useDefaultWebProxy="true">
     <readerQuotas maxDepth="32" maxStringContentLength="10500" maxArrayLength="16384"
      maxBytesPerRead="4096" maxNameTableCharCount="16384" />
        <security mode="Transport">
      <transport clientCredentialType="None" proxyCredentialType="None"
       realm="" />
      <message clientCredentialType="UserName" algorithmSuite="Default" />
     </security>
    </binding>
</basicHttpBinding>
  

<endpoint address="SMS.asmx"
    binding="basicHttpBinding" bindingConfiguration="IBulkSMS"
    contract="IBulkSMS.IBulkSMS" name="IBulkSMS" >
     <identity>
     <servicePrincipalName value="host/MachineName" />
    </identity>
    </endpoint>

2 个答案:

答案 0 :(得分:2)

最后,我得到了解决问题的解决方案。

在生产服务器中禁用代理设置。

  

如果禁用代理,请设置useDefaultWebProxy =“false”。组   如果启用了代理,则使用useDefaultWebProxy =“true”。

我在绑定中做了以下更改。

<binding name="IBulkSMS" closeTimeout="00:10:00" openTimeout="00:10:00"
     receiveTimeout="00:10:00" sendTimeout="00:10:00" allowCookies="false"
     bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
     maxBufferSize="4194304" maxBufferPoolSize="524288" maxReceivedMessageSize="4194304"
     messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
     useDefaultWebProxy="false">

工作正常。

答案 1 :(得分:-1)

在客户端应用程序中设置useDefaultWebProxy="false"