首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >WcfTestClient:合同'IMetadataExchange‘错误

WcfTestClient:合同'IMetadataExchange‘错误
EN

Stack Overflow用户
提问于 2011-07-15 10:01:38
回答 1查看 11.9K关注 0票数 2

我创建了WCF服务应用程序--在运行WcfTestClient之前没有错误。它需要配置IMetadataExchange

如何配置或避免使用IMetadataExchange

错误:

-客户端配置中的合同'IMetadataExchange‘与服务合同中的名称不匹配,或者这份合同中没有有效的方法。若要恢复,请手动更正客户端配置。

或还原到默认配置。

或者在Tools -> Options菜单中检查“启动服务时总是重新生成配置”,然后刷新服务。

App.config

代码语言:javascript
复制
<system.serviceModel>
    <services>
      <service name="WcfCrmService.PermitTypesService">
        <endpoint address="" binding="wsHttpBinding" contract="WcfCrmService.IPermitTypesService">
          <identity>
            <dns value="localhost" />
          </identity>
        </endpoint>
        <endpoint address="mex" binding="mexHttpBinding" contract="WcfCrmService.IPermitTypesService" />
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost:8732/Design_Time_Addresses/WcfCrmService/Mex/" />
          </baseAddresses>
        </host>
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <!-- To avoid disclosing metadata information, 
          set the value below to false and remove the metadata endpoint above before deployment -->
          <serviceMetadata httpGetEnabled="True"/>
          <!-- To receive exception details in faults for debugging purposes, 
          set the value below to true.  Set to false before deployment 
          to avoid disclosing exception information -->
          <serviceDebug includeExceptionDetailInFaults="False"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>

PermitTypes

代码语言:javascript
复制
using System;
using System.Runtime.Serialization;

namespace WcfCrmService
{
    namespace TestService
    {
        [DataContract]
        public class PermitTypes
        {
            [DataMember]
            public Guid PermitTypesId;

            [DataMember]
            public String PermitName;

            [DataMember]
            public String PermitForm;

            [DataMember]
            public String PermitView;
        }
    }
}

IPermitTypesService

代码语言:javascript
复制
using System.Collections.Generic;
using System.ServiceModel;
using WcfCrmService.TestService;

namespace WcfCrmService
{
    [ServiceContract]
    public interface IPermitTypesService
    {
        [OperationContract]
        void SubmitPermitTypes(PermitTypes permit);

        [OperationContract]
        List<PermitTypes> GetPermitTypes();

        [OperationContract]
        void DeletePermitTypes(string id);
    }
}

PermitTypesService

代码语言:javascript
复制
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.ServiceModel;
using System.ServiceModel.Description;
using Microsoft.Crm.Sdk.SWSE;
using Microsoft.Xrm.Sdk;
using Microsoft.Xrm.Sdk.Client;
using WcfCrmService.TestService;
namespace WcfCrmService
{
    [ServiceBehavior(InstanceContextMode = InstanceContextMode.Single)]
    public class PermitTypesService : IPermitTypesService
    {
        public void SubmitPermitTypes(PermitTypes permit)
        {
            // Create records
        }
        public List<PermitTypes> GetPermitTypes()
        {
            // return Results
        }
        public void DeletePermitTypes(string id)
        {
            // Remove items
        }
    }
}

服务XML

代码语言:javascript
复制
<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope" xmlns:a="http://www.w3.org/2005/08/addressing" xmlns:u="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
  <s:Header>
    <a:Action s:mustUnderstand="1" u:Id="_2">http://tempuri.org/IPermitTypesService/GetPermitTypesResponse</a:Action>
    <a:RelatesTo u:Id="_3">urn:uuid:6f8c2229-da22-4ea1-b0df-e760bf51af6d</a:RelatesTo>
    <o:Security s:mustUnderstand="1" xmlns:o="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
      <u:Timestamp u:Id="uuid-090f17e6-f7a7-4e9c-8881-d19571706129-17">
        <u:Created>2011-07-15T10:35:14.132Z</u:Created>
        <u:Expires>2011-07-15T10:40:14.132Z</u:Expires>
      </u:Timestamp>
      <c:DerivedKeyToken u:Id="uuid-090f17e6-f7a7-4e9c-8881-d19571706129-7" xmlns:c="http://schemas.xmlsoap.org/ws/2005/02/sc">
        <o:SecurityTokenReference>
          <o:Reference URI="urn:uuid:1716f576-883e-475c-9b56-4accac413b66" ValueType="http://schemas.xmlsoap.org/ws/2005/02/sc/sct" />
        </o:SecurityTokenReference>
        <c:Offset>0</c:Offset>
        <c:Length>24</c:Length>
        <c:Nonce>GAplsFZPK8LsfnWQDwrTkQ==</c:Nonce>
      </c:DerivedKeyToken>
      <c:DerivedKeyToken u:Id="uuid-090f17e6-f7a7-4e9c-8881-d19571706129-8" xmlns:c="http://schemas.xmlsoap.org/ws/2005/02/sc">
        <o:SecurityTokenReference>
          <o:Reference URI="urn:uuid:1716f576-883e-475c-9b56-4accac413b66" ValueType="http://schemas.xmlsoap.org/ws/2005/02/sc/sct" />
        </o:SecurityTokenReference>
        <c:Nonce>xwL0WRp3kTTqjzEwwFnA3A==</c:Nonce>
      </c:DerivedKeyToken>
      <e:ReferenceList xmlns:e="http://www.w3.org/2001/04/xmlenc#">
        <e:DataReference URI="#_1" />
        <e:DataReference URI="#_4" />
      </e:ReferenceList>
      <e:EncryptedData Id="_4" Type="http://www.w3.org/2001/04/xmlenc#Element" xmlns:e="http://www.w3.org/2001/04/xmlenc#">
        <e:EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#aes256-cbc" />
        <KeyInfo xmlns="http://www.w3.org/2000/09/xmldsig#">
          <o:SecurityTokenReference>
            <o:Reference ValueType="http://schemas.xmlsoap.org/ws/2005/02/sc/dk" URI="#uuid-090f17e6-f7a7-4e9c-8881-d19571706129-8" />
          </o:SecurityTokenReference>
        </KeyInfo>
        <e:CipherData>
          <e:CipherValue>CIPHERDATAK</e:CipherValue>
        </e:CipherData>
      </e:EncryptedData>
    </o:Security>
  </s:Header>
  <s:Body u:Id="_0">
    <GetPermitTypesResponse xmlns="http://tempuri.org/">
      <GetPermitTypesResult xmlns:a="http://schemas.datacontract.org/2004/07/WcfCrmService.TestService" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
        <a:PermitTypes>
          <a:PermitForm>TESTPERMIT_FORM</a:PermitForm>
          <a:PermitName>TESTPERMIT_NAME</a:PermitName>
          <a:PermitTypesId>d81a9ccd-bbae-e011-9b4f-bcaec545c264</a:PermitTypesId>
          <a:PermitView>TESTPERMIT_VIEW</a:PermitView>
        </a:PermitTypes>
        <a:PermitTypes>
          <a:PermitForm>BcisCertificate</a:PermitForm>
          <a:PermitName>Сертификат соответствия БЦИС</a:PermitName>
          <a:PermitTypesId>167ac5ea-51a9-e011-9c96-bcaec545c264</a:PermitTypesId>
          <a:PermitView>BcisCertificateView</a:PermitView>
        </a:PermitTypes>
        <a:PermitTypes>
          <a:PermitForm>DLOReferenceForm</a:PermitForm>
          <a:PermitName>Справка ДЛО</a:PermitName>
          <a:PermitTypesId>16579d03-52a9-e011-9c96-bcaec545c264</a:PermitTypesId>
          <a:PermitView>DLOReferenceView</a:PermitView>
        </a:PermitTypes>
      </GetPermitTypesResult>
    </GetPermitTypesResponse>
  </s:Body>
</s:Envelope>

苏尔坦

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2011-07-15 10:37:59

在您的配置中,这显然是错误的:

代码语言:javascript
复制
<endpoint address="mex" binding="mexHttpBinding" contract="WcfCrmService.IPermitTypesService" />

用于元数据交换的MEX端点必须是,必须具有WCF内建契约IMetadataExchange,而不是您自己的服务契约。

试着使用以下方法:

代码语言:javascript
复制
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />

现在起作用了吗??WCF测试客户端将使用MEX端点来了解您的服务--如果您在那里有错误的服务合同,测试客户机肯定不会工作.

更新:您选择的基本地址也有点奇怪:

代码语言:javascript
复制
<baseAddresses>
   <add baseAddress="http://localhost:8732/Design_Time_Addresses/WcfCrmService/Mex/" />
</baseAddresses>

这意味着:您的实际服务可以访问:

代码语言:javascript
复制
http://localhost:8732/Design_Time_Addresses/WcfCrmService/Mex/

当您的MEX端点在以下位置到达时:

代码语言:javascript
复制
http://localhost:8732/Design_Time_Addresses/WcfCrmService/Mex/mex/

我建议为服务使用更好/更有意义的基址,只需将mex添加到MEX端点的末尾:

代码语言:javascript
复制
<baseAddresses>
   <add baseAddress="http://localhost:8732/Services/WcfCrmService/" />
</baseAddresses>
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/6705405

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档