2010-08-19 169 views
0

連接到WCF服務我在VS 2010錯誤從.NET客戶端

創建了一個新的WCF項目,默認模板然後我創建了一個控制檯應用程序作爲一個客戶端連接到WCF服務。

這裏是我用來連接到服務代碼:

ServiceReference1.Service1Client client = new ServiceReference1.Service1Client(); 

CompositeType ctype = client.GetDataUsingDataContract(new CompositeType()); 

當代碼獲取到它試圖調用該方法GetDataUsingDataContract(),我得到以下異常:

Error creating the Web Proxy specified in the 'system.net/defaultProxy' configuration section. 

Server stack trace: 
    at System.Net.Configuration.DefaultProxySectionInternal.GetSection() 
    at System.Net.WebRequest.get_InternalDefaultWebProxy() 
    at System.Net.HttpWebRequest..ctor(Uri uri, ServicePoint servicePoint) 
    at System.Net.HttpRequestCreator.Create(Uri Uri) 
    at System.Net.WebRequest.Create(Uri requestUri, Boolean useUriBase) 
    at System.Net.WebRequest.Create(Uri requestUri) 
    at System.ServiceModel.Channels.HttpChannelFactory.GetWebRequest(EndpointAddress to, Uri via, NetworkCredential credential, TokenImpersonationLevel impersonationLevel, AuthenticationLevel authenticationLevel, SecurityTokenProviderContainer proxyTokenProvider, SecurityTokenContainer clientCertificateToken, TimeSpan timeout) 
    at System.ServiceModel.Channels.HttpChannelFactory.GetWebRequest(EndpointAddress to, Uri via, SecurityTokenProviderContainer tokenProvider, SecurityTokenProviderContainer proxyTokenProvider, SecurityTokenContainer clientCertificateToken, TimeSpan timeout) 
    at System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.GetWebRequest(EndpointAddress to, Uri via, SecurityTokenContainer clientCertificateToken, TimeoutHelper& timeoutHelper) 
    at System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.GetWebRequest(EndpointAddress to, Uri via, TimeoutHelper& timeoutHelper) 
    at System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelRequest.SendRequest(Message message, TimeSpan timeout) 
    at System.ServiceModel.Channels.RequestChannel.Request(Message message, TimeSpan timeout) 
    at System.ServiceModel.Dispatcher.RequestChannelBinder.Request(Message message, TimeSpan timeout) 
    at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout) 
    at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation) 
    at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message) 

Exception rethrown at [0]: 
    at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg) 
    at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type) 
    at WcfTestClient.ServiceReference1.IService1.GetDataUsingDataContract(CompositeType composite) 
    at WcfTestClient.ServiceReference1.Service1Client.GetDataUsingDataContract(CompositeType composite) in H:\My .NET Projects\WcfTest\WcfTestClient\Service References\ServiceReference1\Reference.cs:line 120 
    at WcfTestClient.Program.Main(String[] args) in H:\My .NET Projects\WcfTest\WcfTestClient\Program.cs:line 15 
    at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args) 
    at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args) 
    at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly() 
    at System.Threading.ThreadHelper.ThreadStart_Context(Object state) 
    at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx) 
    at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) 
    at System.Threading.ThreadHelper.ThreadStart() 

客戶端的app.config

<?xml version="1.0" encoding="utf-8" ?> 
<configuration> 
    <system.serviceModel> 
     <bindings> 
      <basicHttpBinding> 
       <binding name="BasicHttpBinding_IService1" closeTimeout="00:01:00" 
        openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" 
        allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" 
        maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536" 
        messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered" 
        useDefaultWebProxy="false"> 
        <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384" 
         maxBytesPerRead="4096" maxNameTableCharCount="16384" /> 
        <security mode="None"> 
         <transport clientCredentialType="None" proxyCredentialType="None" 
          realm="" /> 
         <message clientCredentialType="UserName" algorithmSuite="Default" /> 
        </security> 
       </binding> 
      </basicHttpBinding> 
     </bindings> 
     <client> 
      <endpoint address="http://localhost:61704/Service1.svc" binding="basicHttpBinding" 
       bindingConfiguration="BasicHttpBinding_IService1" contract="ServiceReference1.IService1" 
       name="BasicHttpBinding_IService1" /> 
     </client> 
    </system.serviceModel> 
</configuration> 

我知道有沒有錯SE服務器和客戶端,因爲我將它複製到另一臺機器上,並且它連接起來,稱爲方法,並返回結果沒有問題。

在我的本地機器上有一些設置阻止我連接到此服務?

請幫忙!!!

謝謝

+0

你設法解決這個問題嗎?我也在經歷它。 – Giorgi 2011-05-25 14:03:23

回答

0

服務託管在哪裏,它是否在IIS的另一臺機器上運行?該服務是否由Visual Studio的開發Web服務器Casini託管運行?

如果它由IIS託管,客戶端上的瀏覽器是否可以通過「開心您創建服務消息」來從服務器查看.svc文件?

+0

我已經嘗試通過Visual Studio中的開發Web服務器託管它,並通過本地IIS服務器託管它。 在這兩種情況下,我都可以瀏覽到.svc文件而沒有問題。 – thiag0 2010-08-19 03:26:49

0

嘗試使用Service Trace Viewer來追蹤你的問題。

一旦你的日誌生成並加載到查看器中,你會發現這個問題很快。這個問題可以是任何不妥協的配置,數據對象不能正確序列化爲WCF代碼中引發的異常。

+0

您是否有可用的鏈接來創建Service Trace Viewer的日誌文件? – thiag0 2010-08-19 03:42:36

+0

@ thiag0檢查[此鏈接](http://msdn.microsoft.com/en-us/library/ms732023.aspx) – slugster 2010-08-19 05:23:39

+0

我想出瞭如何使用服務跟蹤查看器,但我認爲它不會幫助這個情況。服務跟蹤查看器需要一個日誌文件,爲了記錄事情,客戶端需要與服務器進行交互。 它看起來像客戶端可以連接到服務之前發生的問題,因此沒有寫入日誌。 – thiag0 2010-08-20 16:31:34

2

好,閱讀錯誤消息:

錯誤創建代理 在 'system.net/defaultProxy' 配置部分中指定的Web。

所以 - 你能告訴我們在你的web.config文件中定義的<system.net>/<defaultProxy>的值嗎?最有可能的東西有點腥......

+0

我已經檢查了web.config,在那裏沒有定義/。 – thiag0 2010-08-19 20:47:18

+0

然後嘗試創建綁定配置並設置useDefaultProxy = false。 – 2010-08-19 21:16:10

+0

@拉迪斯拉夫 - 試圖將其設置爲假,但仍然不行。還有其他建議嗎? – thiag0 2010-08-20 16:28:40