views:

450

answers:

1

I'm trying to call a webservice method like this:

myService.Register("mystring");

The webmethod definition is just:

[WebMethod]
public void Register(string s)
{
}

But I receive the following System.InvalidOperationException:

"The type System.String was not expected. Use the XmlInclude or SoapInclude attribute to specify types that are not known statically."


   at System.Xml.Serialization.AccessorCollection.findAccessor(Type t)
   at System.Xml.Serialization.XmlSerializationWriter.EnqueueMember(MemberValueCollection members, LogicalMemberValue member, SerializationQueue attributes, SerializationQueue elements, Object fetcherTarget, String parentElementNamespace)
   at System.Xml.Serialization.XmlSerializationWriter.EnqueueMembers(MemberValueCollection members, SerializationQueue attributes, SerializationQueue elements, Object fetcherTarget, String parentElementNamespace)
   at System.Xml.Serialization.XmlSerializationWriter.SerializeComplexAsElement(LogicalType serializeAs, Accessor accessor, Object value, SerializationQueue delayedWork, Boolean recursiveCall, Boolean requiresTypeAttr, XmlSerializerNamespaces serializerNs)
   at System.Web.Services.Protocols.SoapMessageFormatter.SerializeComplexAsElement(LogicalType serializeAs, Accessor accessor, Object value, SerializationQueue delayedWork, Boolean recursiveCall, Boolean requiresTypeAttr, XmlSerializerNamespaces ns)
   at System.Xml.Serialization.XmlSerializationWriter.SerializeAsElement(Accessor accessor, Object value, Object fetcherTarget, SerializationQueue delayedWork, Boolean recursiveCall, Boolean schemaReqTypeAttr, XmlSerializerNamespaces serializerNs)
   at System.Xml.Serialization.XmlSerializationWriter.serializeMembers(SerializationQueue queue, SerializationQueue delayedWork, Boolean recursiveCall, Boolean schemaReqTypeAttr, XmlSerializerNamespaces serializeNs)
   at System.Web.Services.Protocols.SoapMessageFormatter.execute(String targetNamespace)
   at System.Web.Services.Protocols.SoapMessageSerializer.Serialize(XmlWriter writer, SoapHttpClientProtocol client, Object[] parameters, LogicalSoapMethod soapMethod, Boolean soap12)
   at System.Web.Services.Protocols.SoapHttpClientProtocol.doInvoke(String methodName, Object[] parameters, WebClientAsyncResult asyncResult)
   at System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String methodName, Object[] parameters)


Google isn't turning up anything useful and I'm at a dead-end so suggestions would be welcome. My only thought so far is that it's some kind of mismatch because CF uses a different version of the System.dll to the webservice project.

A: 

This was caused by the fact I was using a subclass of the web reference, and also using an interface, i.e.:

public class MyWebServiceReference : RawWebServiceReference, IService {}

The interface was in a separate project to the RawWebServiceReference and MyWebServiceReference, and some aspect of this was causing the error.