开发者

WCF AddServiceReference causing custom tool error, not producing proxy

开发者 https://www.devze.com 2022-12-11 02:11 出处:网络
A problem with \"Add Service Reference\", and actually with SvcUtil over all its features. In order to reproduce you just need to add an OperationContract with argument or returning the following clas

A problem with "Add Service Reference", and actually with SvcUtil over all its features. In order to reproduce you just need to add an OperationContract with argument or returning the following class :

[XmlSchemaProvider("MySchema")]
public class MyStructure : IXmlSerializable
{
    private XmlElement e;

    private static void Func(object o, ValidationEventArgs args)
    {
    }

    public static XmlQualifiedName MySchema(XmlSchemaSet xs)
    {
        //xs.XmlResolver = new XmlUrlResolver();             
        XmlSchema s = XmlSchema.Read(new XmlTextReader(new StringReader("<?xml version=\"1.0\"?><xs:schema xmlns:xs=\"http://www.w3.org/2001/XMLSchema\"><xs:complexType name=\"MyStructure\"><xs:sequence><xs:any /></xs:sequence></xs:complexType></xs:schema>")), null);

        xs.Add(s);
        return new XmlQualifiedName("MyStructure");
    }

    #region IXmlSerializable Members

    public System.Xml.Schema.XmlSchema GetSchema()
    {
        throw new NotImplementedException();
    }

    public void ReadXml(XmlReader reader)
    {
       XmlDocument doc = new XmlDocument();
       e = (XmlElement)doc.ReadNode(reader);
    }

    public void WriteXml(XmlWriter writer)
    {
        e.WriteTo(writer);
    }

    #endregion
}

The result is that when you use AddWebReference or AddSerivceReference without a reference to the class library containing the MyStructure type, everything will be fine ad you will get an xmlElement representation at the auto created proxy.

However, when you have a reference you will get the following warning :

================

Warning 1 Custom tool warning: Cannot import wsdl:portType Detail: An exception was thrown while running a WSDL import extension: System.ServiceModel.Description.DataContractSerializerMessageContractImporter Error: Referenced type 'ServiceLibrary.MyStructure, ServiceLibrary, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' with data contract name 'MyStructure' in namespace '' cannot be used since it does not match import开发者_开发技巧ed DataContract. Need to exclude this type from referenced types. XPath to Error Source: //wsdl:definitions[@targetNamespace='http://tempuri.org/']/wsdl:portType[@name='IService1'] \Projects\WCFSample\WCFExample\TestAddReference\Service References\ServiceReference1\Reference.svcmap 1 1 TestAddReference

======================

And no proxy will be generated for you.

Now, the internet is full with descriptions of this when you have a generic DataContract, and/or using IsReference attribute.

This is a much serious problem, since any non-typed data will do this problem. Could not find any way to solve the problem. What if I want to know the type at the client side, by sharing the class library of the contracts ?


This type of exception generally means there is at least one difference in the type contracts generated by the service as compared to the referenced types (as the message indicates!). But it may not be obvious at first glance, as I found out. Make sure all nested and referenced types are up to date with the server. In my case, nested types were updated on the server. I thought I had updated by locally referenced assembly (and the shared reference types) but I missed some. It took close examination to find the culprit.

See additional information in this question


I have a suggestion:
I had similar errors, including:

the .svcmap file cannot be found. It may have been moved or deleted. To generate a new .svcmap file, delete the service reference and add it again.

And at that point, no way to delete the service reference unless I close VS2010 and open it again.

The situation is: my WCF service is running, I programmatically added a Description.ServiceMetadataBehavior at an HTTP address that I define.

In VS2010, I try to add a service reference at the HTTP address, I see my service, I add the reference, and voila, errors and warning.

The problem: my HTTP address is containing some key words that WCF doesn't like. Specifically the word COM (it breaks with LPT too).

So my solution: modify my HTTP address not to have the word COM. It worked for me.


If the service is hosted over HTTPS, go into the server's IIS Manager. Under "SSL Settings" for the site, make sure "Require SSL" is checked, and check the Client Certificates radio button for "Accept".

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号