代码之家  ›  专栏  ›  技术社区  ›  thiag0

从.NET客户端连接到WCF服务时出错[已关闭]

  •  1
  • thiag0  · 技术社区  · 14 年前

    我用VS2010中的默认模板创建了一个新的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>
    

    我知道服务和客户机没有问题,因为我将它复制到另一台机器上,然后它连接起来,调用方法,并返回结果,没有问题。

    本地计算机上是否存在阻止我连接到此服务的设置?

    请帮忙!!!

    谢谢

    3 回复  |  直到 14 年前
        1
  •  2
  •   marc_s Anurag    14 年前

    好吧,请阅读错误消息:

    创建Web代理时出错 在 '系统.NET/DefaultProxy' 配置部分。

    你能给我们看看 <system.net>/<defaultProxy> 在web.config中??很可能有点可疑……

        2
  •  0
  •   Chris O    14 年前

    服务托管在哪里?例如,它是否在IIS中的另一台计算机上运行?该服务是否由visual studio的开发web服务器casini托管?

    如果它是由IIS托管的,客户端上的浏览器是否可以从服务器上查看.svc文件并显示“很高兴您创建了服务消息”?

        3
  •  0
  •   slugster Joey Cai    14 年前

    尝试使用 Service Trace Viewer 找出你的问题所在。

    一旦生成日志并将其加载到查看器中,您将很快发现问题。问题可能是任何事情,从不可靠的配置到数据对象没有正确序列化,再到在wcf代码中引发异常。