使用 - Web Services Contract First样本无法找到合同名称

时间:2014-11-04 21:18:09

标签: wcf

我是WCF的新手,我创建了一个简单的WCF应用程序(Contract First示例)。但是获取服务文件的错误。任何帮助都会很棒。

  1. 使用VS 2010创建项目 - 选择WCF应用程序。

  2. 删除Iservice1和Service1.svc,然后相应地更新web.config

  3. 在XSD文件夹中添加了模式

  4. 右键单击CustomerMesages.xsd创建.WSDL,选择WSCF.blue - 选择'创建WSDL接口描述'

  5. 创建.WSDL后,右键单击.wsdl文件创建Web服务代码,选择WSCF.blue - 选择'生成Web服务代码'

  6. 将.SVC文件添加到项目

  7. 删除创建的接口文件。

  8. 更新.svc和web.config

  9. 错误:合同名称' XXXXXXService.XXXXXService'无法在服务' XXXXXXService实施的合同列表中找到。

            <?xml version="1.0" encoding="utf-8"?>
        <xs:schema id="Cust_Input"
            targetNamespace="http://tempuri.org/ServiceDemo:data"
            elementFormDefault="qualified"
            xmlns="http://tempuri.org/ServiceDemo:data"
            xmlns:mstns="http://tempuri.org/ServiceDemo:data"
           xmlns:xs="http://www.w3.org/2001/XMLSchema">
    
          <xs:complexType name="GetCustDetailsInput">
            <xs:sequence>
              <xs:element name="KEY" minOccurs="1" maxOccurs="1">
                <xs:complexType>
                  <xs:sequence>
                    <xs:element name="CUST_ID"  minOccurs="1" maxOccurs="1" >
                      <xs:simpleType>
                        <xs:restriction base="xs:double">
                          <xs:minInclusive value="0"></xs:minInclusive>
                          <xs:maxInclusive value="99999999999"></xs:maxInclusive>
                        </xs:restriction>
                      </xs:simpleType>
                    </xs:element>            
                  </xs:sequence>
                </xs:complexType>
              </xs:element>
            </xs:sequence>
          </xs:complexType>
          <xs:element name="GetCustDetailsInput" type="GetCustDetailsInput"></xs:element>
        </xs:schema>
    
          <?xml version="1.0" encoding="utf-8"?>
        <xs:schema id="Cust_Output"
            targetNamespace="http://tempuri.org/ServiceDemo:data"
            elementFormDefault="qualified"
            xmlns="http://tempuri.org/ServiceDemo:data"
            xmlns:mstns="http://tempuri.org/ServiceDemo:data"
            xmlns:xs="http://www.w3.org/2001/XMLSchema">
    
          <xs:complexType name="GetCustDetailsOutput">
            <xs:sequence>     
              <xs:element name="KEY" minOccurs="0" maxOccurs="1">
                <xs:complexType>
                  <xs:sequence>
                    <xs:element name="L_Name" type="xs:string" minOccurs="1" maxOccurs="1"/>
                    <xs:element name="F_Name" type="xs:string" minOccurs="1" maxOccurs="1" />
                    <xs:element name="ERR_MSG" type="xs:string" minOccurs="1" maxOccurs="1" />
                  </xs:sequence>
                </xs:complexType>
              </xs:element>
            </xs:sequence>
          </xs:complexType>
          <xs:element type="GetCustDetailsOutput" name="GetCustDetailsOutput"></xs:element>
        </xs:schema>
    
          <?xml version="1.0" encoding="utf-8"?>
        <xs:schema id="CustomerMessages"
            targetNamespace="http://tempuri.org/ServiceDemo:messages"
            elementFormDefault="qualified"
            xmlns="http://tempuri.org/ServiceDemo:messages"
            xmlns:mstns="http://tempuri.org/ServiceDemo:messages"
            xmlns:xs="http://www.w3.org/2001/XMLSchema"
            xmlns:input="http://tempuri.org/ServiceDemo:data"
            xmlns:output="http://tempuri.org/ServiceDemo:data">
    
          <xs:import id="GetCustDetailsInputXsd" schemaLocation="Cust_Input.xsd" namespace="http://tempuri.org/ServiceDemo:data"/>
          <xs:import id="GetCustDetailsOutputXsd" schemaLocation="Cust_Output.xsd" namespace="http://tempuri.org/ServiceDemo:data"/>
    
          <xs:complexType name="GetCustDetailsRequest">
            <xs:sequence>
              <xs:element name="GetCustDetailsInput" type="input:GetCustDetailsInput"/>
            </xs:sequence>
          </xs:complexType>
          <xs:element name="GetCustDetailsRequest"  type="mstns:GetCustDetailsRequest"></xs:element>
          <xs:complexType name="GetCustDetailsResponse">
            <xs:sequence>
              <xs:element name="GetCustDetailsOutput" type="output:GetCustDetailsOutput"/>
            </xs:sequence>
          </xs:complexType>
          <xs:element name="GetCustDetailsResponse" type="mstns:GetCustDetailsResponse"/>
        </xs:schema>
    
  10. 添加web.config服务模型部分

        <system.serviceModel>
    <services>
      <service behaviorConfiguration="CustomerService.CustomerTestServiceBehavior"
        name="CustomerService.CustomerTestService">
        <endpoint address="" binding="wsHttpBinding" contract="CustomerService.CustomerService">
          <identity>
            <dns value="localhost" />
          </identity>
        </endpoint>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="CustomerService.CustomerTestServiceBehavior">
          <serviceMetadata httpGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="false" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
    

    CustomerService.CustomerService代码: 命名空间CustomerService {

    [System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
    [System.ServiceModel.ServiceContractAttribute(Namespace="http://tempuri.org/demos:ServiceDemo", ConfigurationName="ICustomerService")]
    public interface ICustomerService
    {
    
        // CODEGEN: Generating message contract since the wrapper namespace (http://tempuri.org/ServiceDemo:messages) of message GetCustDetailsRequest does not match the default value (http://tempuri.org/demos:ServiceDemo)
        [System.ServiceModel.OperationContractAttribute(Action="http://tempuri.org/demos:ServiceDemo/ICustomerService/GetCustDetails", ReplyAction="http://tempuri.org/demos:ServiceDemo/ICustomerService/GetCustDetailsResponse")]
        [System.ServiceModel.XmlSerializerFormatAttribute(SupportFaults=true)]
        GetCustDetailsResponse GetCustDetails(GetCustDetailsRequest request);
    }
    
    /// <remarks/>
    [System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.0.30319.34234")]
    [System.SerializableAttribute()]
    [System.Diagnostics.DebuggerStepThroughAttribute()]
    [System.ComponentModel.DesignerCategoryAttribute("code")]
    [System.Xml.Serialization.XmlTypeAttribute(Namespace="http://tempuri.org/ServiceDemo:data")]
    public partial class GetCustDetailsInput : object, System.ComponentModel.INotifyPropertyChanged
    {
    
        private GetCustDetailsInputKEY kEYField;
    
        /// <remarks/>
        public GetCustDetailsInputKEY KEY
        {
            get
            {
                return this.kEYField;
            }
            set
            {
                this.kEYField = value;
                this.RaisePropertyChanged("KEY");
            }
        }       
    
    }
    
    ......
    .....
    
    public class ObjectCollection : System.Collections.ObjectModel.Collection<object>
    {
    }
    
    [System.ServiceModel.ServiceBehaviorAttribute(InstanceContextMode=System.ServiceModel.InstanceContextMode.PerCall, ConcurrencyMode=System.ServiceModel.ConcurrencyMode.Single)]
    public partial class CustomerService : ICustomerService
    {
    
        public virtual GetCustDetailsResponse GetCustDetails(GetCustDetailsRequest request)
        {
            throw new System.NotImplementedException();
        }
    }
    

    }

0 个答案:

没有答案