无法从c#.net应用程序访问服务器上托管的WCF服务

时间:2013-07-18 18:50:51

标签: performance wcf wcf-data-services wcf-binding wcf-security

我已经创建了一个WCF服务来联系sql数据库。

我在远程服务器IIS上托管了该服务。

运行服务,可以从IIS浏览。 IIS Browse返回服务URL,如下所示。

当我尝试从服务器外部(即从我的本地系统)访问服务时,它会抛出错误。 我尝试使用系统IP而不是域名,我可以通过IE()

访问服务

当我尝试在我的.net应用程序上添加服务时,它会抛出错误。

添加服务参考中的错误消息:

<!--The document was understood, but it could not be processed.
  - The WSDL document contains links that could not be resolved.
  - There was an error downloading '<!--http://sysname:4567/Service1.svc?xsd=xsd0'.
  - The remote name could not be resolved: 'sysname'
Metadata contains a reference that cannot be resolved: 'http://ipaddress:4567/Service1.svc?wsdl'.
Metadata contains a reference that cannot be resolved: 'http://ipaddress:4567/Service1.svc?wsdl'.
If the service is defined in the current solution, try building the solution and adding the service reference again.-->

Error Message From svcutil.exe:

<!--Error: Cannot obtain Metadata from http://http//ipaddress:4567/Service1.svc
?wsdl
If this is a Windows (R) Communication Foundation service to which you have acce
ss, please check that you have enabled metadata publishing at the specified addr
ess.  For help enabling metadata publishing, please refer to the MSDN documentat
ion at http://go.microsoft.com/fwlink/?LinkId=65455.
WS-Metadata Exchange Error
    URI: http://http//ipaddress:4567/Service1.svc?wsdl
    Metadata contains a reference that cannot be resolved: 'http://http//ipaddres:4567/Service1.svc?wsdl'.
    There was no endpoint listening at http://http//ipaddress:4567/Service1
.svc?wsdl that could accept the message. This is often caused by an incorrect ad
dress or SOAP action. See InnerException, if present, for more details.
    The remote name could not be resolved: 'http'
HTTP GET Error
    URI: http://http//ipaddress:4567/Service1.svc?wsdl
    There was an error downloading 'http://http//ipaddress:4567/Service1.sv
c?wsdl'.
    The remote name could not be resolved: 'http'
If you would like more help, type "svcutil /?"-->

这是我的WebConfig文件:

<configuration> 
    <appSettings/>
    <connectionStrings/>
    <system.web>    
        <compilation debug="true">
            <assemblies>
                <add assembly="System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
                <add assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
            </assemblies>
        </compilation>      
        <authentication mode="Windows"/>    
        <pages>
            <controls>
                <add tagPrefix="asp" namespace="System.Web.UI" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
            </controls>
        </pages>
        <httpHandlers>
            <remove verb="*" path="*.asmx"/>
            <add verb="*" path="*.asmx" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
            <add verb="*" path="*_AppService.axd" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
            <add verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" validate="false"/>
        </httpHandlers>
        <httpModules>
            <add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
        </httpModules>
    </system.web>
    <system.codedom>
        <compilers>
            <compiler language="c#;cs;csharp" extension=".cs" warningLevel="4" type="Microsoft.CSharp.CSharpCodeProvider, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
                <providerOption name="CompilerVersion" value="v3.5"/>
                <providerOption name="WarnAsError" value="false"/>
            </compiler>
        </compilers>
    </system.codedom>
    <system.web.extensions>
        <scripting>
            <webServices></webServices>         
        </scripting>
    </system.web.extensions>
    <system.webServer>
        <validation validateIntegratedModeConfiguration="false"/>
        <modules>
            <add name="ScriptModule" preCondition="integratedMode" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
        </modules>
        <handlers>
            <remove name="WebServiceHandlerFactory-Integrated"/>
            <add name="ScriptHandlerFactory" verb="*" path="*.asmx" preCondition="integratedMode" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
            <add name="ScriptHandlerFactoryAppServices" verb="*" path="*_AppService.axd" preCondition="integratedMode" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
            <add name="ScriptResource" preCondition="integratedMode" verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
        </handlers>
    </system.webServer>
    <system.serviceModel>
        <services>
            <service name="portalConnectorService.Service1" behaviorConfiguration="portalConnectorService.Service1Behavior">
                <host>
                  <baseAddresses>
                      <add baseAddress="http://184.73.184.213:4567/Service1.svc"></add>
                  </baseAddresses>
              </host>
                <!- - Service Endpoints - ->
                <endpoint address="" binding="wsHttpBinding" contract="portalConnectorService.IService1">                   
                </endpoint>
                <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
            </service>
        </services>
        <behaviors>
            <serviceBehaviors>
                <behavior name="portalConnectorService.Service1Behavior">                   
                    <serviceMetadata httpGetEnabled="true"/>                    
                    <serviceDebug includeExceptionDetailInFaults="false"/>
                </behavior>
            </serviceBehaviors>
        </behaviors>
    </system.serviceModel>
</configuration>

任何人都可以帮我解决此错误。

1 个答案:

答案 0 :(得分:0)

尝试注释掉指定基址的主机部分。 实际上,IIS已经忽略了它,但无论如何都要尝试。

您收到的实际错误消息是什么?