【发布时间】:2013-08-28 17:30:14
【问题描述】:
我创建了一个简单的 web 服务服务器,但是为了从同一个项目中的服务类调用方法,我创建了一个 webchannelfactory 代理。在我将项目(或 exe 版本)移动到另一台机器之前,一切正常。搞不懂是怎么回事!
我收到此错误消息:
The remote server returned an unexpected response: (400) Bad Request.
使用堆栈跟踪:
Server stack trace:
at System.ServiceModel.Channels.HttpChannelUtilities.ValidateRequestReplyResp
onse(HttpWebRequest request, HttpWebResponse response, HttpChannelFactory factor
y, WebException responseException, ChannelBinding channelBinding)
at System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpCha
nnelRequest.WaitForReply(TimeSpan timeout)
at System.ServiceModel.Channels.RequestChannel.Request(Message message, TimeS
pan timeout)
at System.ServiceModel.Dispatcher.RequestChannelBinder.Request(Message messag
e, TimeSpan timeout)
at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean on
eway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan tim
eout)
at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCall
Message methodCall, ProxyOperationRuntime operation)
at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)
Exception rethrown at [0]:
at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage req
Msg, IMessage retMsg)
at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgDa
ta, Int32 type)
at Client.IClientService.dosomething()
at Host.ClientHost.Start(Uri hostUri, Int32 interval) in C:\(...)
代码:
WebChannelFactory<Client.IClientService> factory = new WebChannelFactory<Client.IClientService>(hostUri);
Client.IClientService proxy = factory.CreateChannel();
proxy.dosomething(); // Error shout here on Machine2
提前致谢
编辑1: 对于此示例,没有客户端(我已将客户端命名为此服务器)。正如我所说,它在另一台机器上运行的代码没有错误(都使用本地主机)。
<?xml version="1.0"?>
<configuration>
<appSettings>
<system.serviceModel>
<bindings>
</bindings>
<services>
<service name="Client.ClientService" behaviorConfiguration="Default">
<endpoint address="" binding="webHttpBinding" contract="Client.IClientService"></endpoint>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="Default">
<serviceMetadata httpGetEnabled="true"></serviceMetadata>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
</startup>
</configuration>
EDIT2:
在浏览器上,我得到了这个:
服务器在处理请求时遇到错误。例外 消息是 'Client.ClientService' 的类型初始化程序抛出了一个 例外。'。有关更多详细信息,请参阅服务器日志。异常堆栈 跟踪是:
在 Client.ClientService..ctor() 在 CreateClient.ClientService() 在 System.ServiceModel.Dispatcher.InstanceProvider.GetInstance(InstanceContext instanceContext,消息消息)在 System.ServiceModel.Dispatcher.InstanceBehavior.GetInstance(InstanceContext instanceContext,消息请求)在 System.ServiceModel.InstanceContext.GetServiceInstance(消息 消息)在 System.ServiceModel.Dispatcher.InstanceBehavior.EnsureServiceInstance(MessageRpc& RPC)在 System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage41(MessageRpc& RPC)在 System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage4(MessageRpc& RPC)在 System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage31(MessageRpc& RPC)在 System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage3(MessageRpc& RPC)在 System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage2(MessageRpc& RPC)在 System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage11(MessageRpc& RPC)在 System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage1(MessageRpc& rpc) 在 System.ServiceModel.Dispatcher.MessageRpc.Process(Boolean isOperationContextSet)
【问题讨论】:
标签: c# wcf proxy webchannelfactory