2013-08-26 52 views
0

我已經創建了一個簡單的web服務服務器,但要在同一個項目中調用服務類中的方法,我創建了一個webchannelfactory代理。一切工作正常,直到我將項目(或exe版本)移動到另一臺機器。我無法弄清楚發生了什麼事情!C#WCF ChannelFactory BadRequest 400錯誤

我收到此錯誤信息:

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: 當t他的例子中,沒有客戶端(我已將客戶端命名爲此服務器)。正如我所說的,它的代碼在另一臺機器上都沒有錯誤(都使用localhost)。

<?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.Immutab leDispatchRuntime.ProcessMessage41(MessageRpc & RPC)處 System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage31(MessageRpc & RPC) System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage4(MessageRpc & RPC)在 System.ServiceModel.Dispatcher .ImmutableDispatchRuntime.ProcessMessage3(MessageRpc & RPC)處 System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage11 System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage2(MessageRpc & RPC)(MessageRpc & RPC)在 System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage1(MessageRpc & RPC)在System.ServiceModel.Dispatcher.MessageRpc.Process(布爾 isOperationContextSet)

回答

0

問題解決了。

服務利用數據庫,所以當我複製項目到一臺新機器,我忘了創建一個新的數據庫。