0

我创建了一个简单的 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

提前致谢

EDIT1:对于这个例子,没有客户端(我已经将客户端命名为这个服务器)。正如我所说,它在另一台机器上运行的代码没有错误(都使用本地主机)。

<?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>

编辑2:

在浏览器上,我得到了这个:

服务器在处理请求时遇到错误。异常消息是“'Client.ClientService' 的类型初始化程序引发了异常。”。有关更多详细信息,请参阅服务器日志。异常堆栈跟踪是:

在 Client.ClientService..ctor() 在 CreateClient.ClientService() 在 System.ServiceModel.Dispatcher.InstanceProvider.GetInstance(InstanceContext instanceContext, Message message) 在 System.ServiceModel.Dispatcher.InstanceBehavior.GetInstance(InstanceContext instanceContext, Message request) 在System.ServiceModel.InstanceContext.GetServiceInstance(Message message) 在 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(布尔 isOperationContextSet)

4

1 回答 1

0

问题解决了。

该服务使用数据库,因此当我将项目复制到新机器时,我忘记创建新数据库。

于 2013-08-26T13:31:36.693 回答