C# 从.NET客户端连接到WCF服务时出错

C# 从.NET客户端连接到WCF服务时出错,c#,.net,wcf,windows-7,proxy,C#,.net,Wcf,Windows 7,Proxy,我在VS2010中使用默认模板创建了一个新的WCF项目 然后我创建了一个控制台应用程序作为客户端连接到WCF服务 以下是我用来连接服务的代码: ServiceReference1.Service1Client client = new ServiceReference1.Service1Client(); CompositeType ctype = client.GetDataUsingDataContract(new CompositeType()); 当代码到达它试图调用方法GetDat

我在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>

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

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

请帮忙


谢谢

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

如果它是由IIS托管的,客户端上的浏览器是否可以查看服务器上的.svc文件,并显示“happy you have create a service message”(很高兴您已创建服务消息)?

尝试使用来跟踪您的问题所在


一旦生成日志并将其加载到查看器中,您将很快发现问题。问题可能是从不可靠的配置到未正确序列化的数据对象,再到WCF代码中引发的异常。好了,请阅读错误消息:

创建Web代理时出错 在 “system.net/defaultProxy” 配置部分


那么-您能否向我们展示您的web.config中
/
中定义的值??这很可能有点可疑….

我曾尝试通过Visual Studio中的开发web服务器托管它,并通过本地IIS服务器托管它。在这两种情况下,我都可以毫无问题地浏览到.svc文件。您是否有关于如何为Service Trace Viewer创建日志文件的链接?@thiag0 check我知道了如何使用Service Trace Viewer,但我认为在这种情况下它不会有帮助。Service Trace Viewer需要一个日志文件,为了将事情记录下来,客户端需要与服务器交互。问题似乎是在客户端连接到服务之前发生的,因此没有写入日志。我已经检查了web.config,其中没有/定义。然后尝试创建绑定配置并将useDefaultProxy设置为false。@Ladislav-尝试将其设置为false,但仍然没有效果。还有其他建议吗?@Ladislav-我已经在上面为客户端的app.config文件添加了代码。你解决了这个问题吗?我也经历过。