我已经获得了一个wcf服务,我构建了一个本地控制台应用程序来测试它,但我不断收到标题中显示的错误。我的服务在浏览器中运行,它显示了显示示例的屏幕以及可以测试它的URL。可能是错误发生在Web.config或App.config中。我有这两个文件:
Web.condig
<?xml version="1.0"?>
<configuration>
<appSettings>
...
</appSettings>
<system.web>
<compilation debug="false" targetFramework="4.0"/>
</system.web>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
<system.serviceModel>
<bindings>
<webHttpBinding>
<binding name="webHttpBindingWithJsonP" crossDomainScriptAccessEnabled="true"/>
</webHttpBinding>
</bindings>
<behaviors>
<endpointBehaviors>
<behavior name="webHttpBehavior">
<webHttp helpEnabled="true"/>
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior>
<serviceMetadata httpGetEnabled="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>
<services>
<service name="RAHPEDWCFService.RAHPEDService">
<endpoint address="http://localhost:44184/RAHPEDService.svc" behaviorConfiguration="webHttpBehavior" binding="webHttpBinding" bindingConfiguration="webHttpBindingWithJsonP" contract="RAHPEDWCFService.IRAHPEDService"/>
</service>
</services>
</system.serviceModel>
</configuration>
的App.config
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IRAHPEDService" 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="true">
<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:44184/RAHPEDService.svc"
binding="basicHttpBinding"
bindingConfiguration="BasicHttpBinding_IRAHPEDService"
contract="ServiceReference.IRAHPEDService"
name="BasicHttpBinding_IRAHPEDService" />
</client>
</system.serviceModel>
</configuration>
我希望有人能给我一个提示。
答案 0 :(得分:0)
您应该检查您是否正在访问正确的地址。而不是在Web.config中指定整个地址,更常见的做法是仅提供相对地址(甚至 一个空的&#34;&#34;很好),然后你用:
访问服务http://servername:[port]/[virtual directory]/RAHPEDWCF.svc/[relative address in Web.config]
E.g。如果Web.config中的地址显示
endpoint address="MySVC"
客户端的完整URL(假设默认端口80和虚拟服务器的根目录)可能是
http://servername/RAHPEDWCF.svc/MySVC
如果您能够修改Web.config,我建议这样做。
答案 1 :(得分:0)
请按照以下步骤解决此问题
能够在浏览器中看到wsdl元数据 如果您的客户端配置文件中有多个端点,那么您已将端点的名称传递给ServiceCleint类的构造函数
打开Visual Studio CommandPrompt并输入WcfTestClient,右键单击MyServiceProjects,添加服务并检查是否能够添加,并且一旦添加调用,您的方法就会出现在端点下