远程服务器 returns 400 上的 WCF 服务,在本地工作正常
WCF Service on remote server returns 400, works fine locally
我制作了一个托管 WCF 服务的小型控制台应用程序,此应用程序也是客户端并实现了该服务。
它在我的本地机器上运行良好,returns 将 JSON 中的数据传输到网络浏览器。我使用带有 Advanced Rest CLient 的 Chrome 浏览器,但也使用 javascript 客户端并成功读取响应。
我在服务器上部署了可执行文件并将端点地址更改为域名。在正确的端口访问域上的服务也显示服务已激活,我也可以远程访问wsdl。
当我尝试 Post 时,我收到一个 http 400 错误请求错误。我无法弄清楚为什么这在本地工作正常但在远程服务器上却不行。
[ServiceContract]
public interface IService
{
[WebInvoke(UriTemplate = "/getRecipes/",
Method = "POST", BodyStyle = WebMessageBodyStyle.Wrapped, ResponseFormat = WebMessageFormat.Json, RequestFormat = WebMessageFormat.Json)]
[OperationContract]
object[][] getRecipes();
}
public class Service : IService
{
private static bool IgnoreCertificateErrorHandler(object Sender,
System.Security.Cryptography.X509Certificates.X509Certificate Cert,
System.Security.Cryptography.X509Certificates.X509Chain Ch,
System.Net.Security.SslPolicyErrors PolErr)
{
return true;
}
public object[][] getRecipes()
{
//this is the place where implement a client implementation of a webservice and it full the object array beneath, this returns more then 200 rows.
object[][] QueryResult;
return QueryResult;
}
}
App.config:
<system.serviceModel>
<services>
<service name="CS.Service" behaviorConfiguration="PageBehave">
<host>
<baseAddresses>
<add baseAddress="http://domain.com:9001/Service"/>
</baseAddresses>
</host>
<endpoint address="http://domain.com:9001/Service" binding="webHttpBinding" behaviorConfiguration="webBehavior" contract="CS.IService"/>
</service>
</services>
<behaviors>
<endpointBehaviors>
<behavior name="webBehavior">
<webHttp/>
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="PageBehave">
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
更新:
此应用程序是与远程网络服务通信的桥梁。目前我得到的错误是:无法解析远程名称:
. The exception stack trace is:
System.Net.HttpWebRequest.GetRequestStream(TransportContext& context)
at System.Net.HttpWebRequest.GetRequestStream()
at System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String methodName, Object[] parameters)
`at ConsoleApplication1.ABC.ABC.select(String sql, Object[] params) in`
c:\Users\---\Desktop\--\--\Web References\ABC\Reference.cs:line 81
at CS.Service.getRecipeDetails(String number) in c:\Users\--\Desktop\---\ConsoleApplication1\Program.cs:line 134
at SyncInvokegetRecipeDetails(Object , Object[] , Object[] )
at System.ServiceModel.Dispatcher.SyncMethodInvoker.Invoke(Object instance, Object[] inputs, Object[]& outputs)
at System.ServiceModel.Dispatcher.DispatchOperationRuntime.InvokeBegin(MessageRpc& rpc)
at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage5(MessageRpc& rpc)
at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage31(MessageRpc& rpc)
at System.ServiceModel.Dispatcher.MessageRpc.Process(Boolean isOperationContextSet)
这个网桥应用程序在我试过的任何本地机器上都能完美运行。只是服务器出问题了。
尝试删除地址属性的值...
<endpoint address="" binding="webHttpBinding" behaviorConfiguration="webBehavior" contract="CS.IService"/>
解决了这个问题。服务器上的主机文件必须包含我试图从 wcf 服务访问的远程服务器。
我制作了一个托管 WCF 服务的小型控制台应用程序,此应用程序也是客户端并实现了该服务。
它在我的本地机器上运行良好,returns 将 JSON 中的数据传输到网络浏览器。我使用带有 Advanced Rest CLient 的 Chrome 浏览器,但也使用 javascript 客户端并成功读取响应。
我在服务器上部署了可执行文件并将端点地址更改为域名。在正确的端口访问域上的服务也显示服务已激活,我也可以远程访问wsdl。
当我尝试 Post 时,我收到一个 http 400 错误请求错误。我无法弄清楚为什么这在本地工作正常但在远程服务器上却不行。
[ServiceContract]
public interface IService
{
[WebInvoke(UriTemplate = "/getRecipes/",
Method = "POST", BodyStyle = WebMessageBodyStyle.Wrapped, ResponseFormat = WebMessageFormat.Json, RequestFormat = WebMessageFormat.Json)]
[OperationContract]
object[][] getRecipes();
}
public class Service : IService
{
private static bool IgnoreCertificateErrorHandler(object Sender,
System.Security.Cryptography.X509Certificates.X509Certificate Cert,
System.Security.Cryptography.X509Certificates.X509Chain Ch,
System.Net.Security.SslPolicyErrors PolErr)
{
return true;
}
public object[][] getRecipes()
{
//this is the place where implement a client implementation of a webservice and it full the object array beneath, this returns more then 200 rows.
object[][] QueryResult;
return QueryResult;
}
}
App.config:
<system.serviceModel>
<services>
<service name="CS.Service" behaviorConfiguration="PageBehave">
<host>
<baseAddresses>
<add baseAddress="http://domain.com:9001/Service"/>
</baseAddresses>
</host>
<endpoint address="http://domain.com:9001/Service" binding="webHttpBinding" behaviorConfiguration="webBehavior" contract="CS.IService"/>
</service>
</services>
<behaviors>
<endpointBehaviors>
<behavior name="webBehavior">
<webHttp/>
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="PageBehave">
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
更新:
此应用程序是与远程网络服务通信的桥梁。目前我得到的错误是:无法解析远程名称:
. The exception stack trace is:
System.Net.HttpWebRequest.GetRequestStream(TransportContext& context)
at System.Net.HttpWebRequest.GetRequestStream()
at System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String methodName, Object[] parameters)
`at ConsoleApplication1.ABC.ABC.select(String sql, Object[] params) in`
c:\Users\---\Desktop\--\--\Web References\ABC\Reference.cs:line 81
at CS.Service.getRecipeDetails(String number) in c:\Users\--\Desktop\---\ConsoleApplication1\Program.cs:line 134
at SyncInvokegetRecipeDetails(Object , Object[] , Object[] )
at System.ServiceModel.Dispatcher.SyncMethodInvoker.Invoke(Object instance, Object[] inputs, Object[]& outputs)
at System.ServiceModel.Dispatcher.DispatchOperationRuntime.InvokeBegin(MessageRpc& rpc)
at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage5(MessageRpc& rpc)
at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage31(MessageRpc& rpc)
at System.ServiceModel.Dispatcher.MessageRpc.Process(Boolean isOperationContextSet)
这个网桥应用程序在我试过的任何本地机器上都能完美运行。只是服务器出问题了。
尝试删除地址属性的值...
<endpoint address="" binding="webHttpBinding" behaviorConfiguration="webBehavior" contract="CS.IService"/>
解决了这个问题。服务器上的主机文件必须包含我试图从 wcf 服务访问的远程服务器。