我制作了一个托管WCF服务的小型控制台应用程序,该应用程序也是客户端并实现了服务。
它在我的本地计算机上运行正常,并将JSON中的数据返回给webbrowser。我使用Chrome浏览器和Advanced Rest CLient,但也使用了javascript客户端并成功阅读了响应。
我在服务器上部署了可执行文件,并将端点adres更改为域名。访问右侧端口上的域上的服务也显示服务已激活,我也可以远程访问wsdl。
当我尝试发帖时,我收到了一个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>
更新:
此应用程序是与远程Web服务进行通信的桥梁。目前我得到的错误是:无法解析远程名称:
. 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)
这个桥接应用程序在我试过的任何本地机器上都能完美运行。只是服务器出了问题。
答案 0 :(得分:1)
尝试删除地址属性的值...
<endpoint address="" binding="webHttpBinding" behaviorConfiguration="webBehavior" contract="CS.IService"/>
答案 1 :(得分:1)
解决了这个问题。服务器上的主机文件必须包含我试图从wcf服务访问的远程服务器。