1

这是我的第一个 WCF 服务,我遇到了新手常见的问题,即配置文件。

服务项目是用herehere的示例创建的,收到错误后,我在这里here[Failed to add a service. Service metadata may not be accessible. Make sure your service is running and exposing metadata.]通过了Web.config的MSDN方式。

这是我的 Web.config:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <system.web>
        <compilation debug="true" targetFramework="4.0" />
    </system.web>
    <system.serviceModel>
        <services>
            <service name="Parkalot.WcfClient.Services.UserService">
                <host>
                    <baseAddresses>
                        <add baseAddress="http://localhost:7349/ServiceMetadata" />
                    </baseAddresses>
                </host>
                <endpoint address="/UserService" binding="wsHttpBinding" contract="Parkalot.WcfClient.Services.IUserServiceContract" />
                <!-- Adds a WS-MetadataExchange endpoint at "http://localhost:7349/ServiceMetadata/mex" -->
                <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
            </service>
        </services>
        <behaviors>
            <serviceBehaviors>
                <behavior name="metadataSupport">
                    <!-- Enables the IMetadataExchange endpoint in services that -->
                    <!-- use "metadataSupport" in their behaviorConfiguration attribute. -->
                    <!-- In addition, the httpGetEnabled and httpGetUrl attributes publish -->
                    <!-- Service metadata for retrieval by HTTP/GET at the address -->
                    <!-- "http://localhost:8080/ServiceMetadata?wsdl" -->
                    <serviceMetadata httpGetEnabled="true" httpGetUrl="http://localhost:7349/ServiceMetadata?wsdl" />
                </behavior>
            </serviceBehaviors>
        </behaviors>
    </system.serviceModel>
</configuration>

错误详情如下:

    Error: Cannot obtain Metadata from http://localhost:7349/Services/UserService.svc
If this is a Windows (R) Communication Foundation service to which you have access, please check that you have enabled metadata publishing at the specified address.
For help enabling metadata publishing, please refer to the MSDN documentation at http://go.microsoft.com/fwlink/?LinkId=65455.
WS-Metadata Exchange Error    URI: http://localhost:7349/Services/UserService.svc
Metadata contains a reference that cannot be resolved:
'http://localhost:7349/Services/UserService.svc'.
The server did not provide a meaningful reply; this might be caused by a contract mismatch, a premature session shutdown or an internal server error.
HTTP GET Error    URI: http://localhost:7349/Services/UserService.svc
There was an error downloading 'http://localhost:7349/Services/UserService.svc'.

我已经从错误中删除了很多行,这可能是为了在浏览器中呈现。因为我是在 Visual Studio 中运行的,所以我没有浏览器上下文。

4

0 回答 0