Microsoft Developer Network > Página principal de foros > SharePoint - Development and Programming > Error calling sharepoint web services from .net 3.5 WCF client...
Formular una preguntaFormular una pregunta
 

Respuesta propuestaError calling sharepoint web services from .net 3.5 WCF client...

  • miércoles, 16 de julio de 2008 20:52SteveCl Medallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuario
     

     

     

    Code Snippet

                    using (OCUserProfileService.UserProfileServiceSoapClient service =
                        new TestAndDestroy.OCUserProfileService.UserProfileServiceSoapClient(GetWcfBinding())) {

                        service.ClientCredentials.Windows.AllowedImpersonationLevel = TokenImpersonationLevel.Impersonation;
                    
                        PropertyData[] properties = service.GetUserProfileByName("domain\\user.name");

                        foreach (PropertyData p in properties) {
                            Console.WriteLine(p.Name);
                            Console.WriteLine(p.Values);
                        }

     

     

     

    produces....
    The formatter threw an exception while trying to deserialize the message: There was an error while trying to deserialize parameter http://microsoft.com/webservices/SharePointPortalServer/UserProfileService:GetUserProfileByNameResponse. The InnerException message was 'Error in line 1 position 392. 'Element' 'IsPrivacyChanged' from namespace 'http://microsoft.com/webservices/SharePointPortalServer/UserProfileService' is not expected. Expecting element 'Name | Privacy'.'.  Please see InnerException for more details.

     

    I'm totally stumped, any ideas???

Todas las respuestas

  • miércoles, 16 de julio de 2008 20:53SteveCl Medallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuario
     
    i should mention that the same code in .net 2.0 works fine....

     

  • viernes, 18 de julio de 2008 16:34charoldson Medallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuario
     

    The good news is I can confirm this behavior.  The bad news is I'm also looking for a fix.  =(

  • lunes, 21 de julio de 2008 20:01kirke Medallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuario
     

    I was able to reproduce as well.  The WSDL doesn't match the shape of the XML that is being returned from SharePoint.  The short-term fix is to change the generated proxy code to match the shape of what SharePoint is actually returning (versus what is exposed in its WSDL).  The actual shape of the message is:

     

    Code Snippet

    <s:complexType name="PropertyData">

    <s:sequence>

    <s:element minOccurs="1" maxOccurs="1" name="IsPrivacyChanged" type="s:boolean" />

    <s:element minOccurs="1" maxOccurs="1" name="IsValueChanged" type="s:boolean" />

    <s:element minOccurs="0" maxOccurs="1" name="Name" type="s:string" />

    <s:element minOccurs="1" maxOccurs="1" name="Privacy" type="s0:Privacy" />

    <s:element minOccurs="0" maxOccurs="1" name="Values" type="s0:ArrayOfValueData" />

    </< FONT></s:sequence>

    </< FONT></s:complexType>

     

     

     

    Notice that the IsPrivacyChanged and IsValueChanged elements need to appear first in the sequence.  For instance, you can change the generated WCF proxy type for the PropertyData class to look like the following:

     

    Code Snippet

    [System.Diagnostics.DebuggerStepThroughAttribute()]

    [System.CodeDom.Compiler.GeneratedCodeAttribute("System.Runtime.Serialization", "3.0.0.0")]

    [System.Runtime.Serialization.DataContractAttribute(Name="PropertyData", Namespace="http://microsoft.com/webservices/SharePointPortalServer/UserProfileService")]

    public partial class PropertyData : object, System.Runtime.Serialization.IExtensibleDataObject

    {

    private System.Runtime.Serialization.ExtensionDataObject extensionDataField;

    private bool IsPrivacyChangedField;

    private bool IsValueChangedField;

    private string NameField;

    private microsoft.com.webservices.SharePointPortalServer.UserProfileService.Privacy PrivacyField;

    private microsoft.com.webservices.SharePointPortalServer.UserProfileService.ValueData[] ValuesField;

    public System.Runtime.Serialization.ExtensionDataObject ExtensionData

    {

    get

    {

    return this.extensionDataField;

    }

    set

    {

    this.extensionDataField = value;

    }

    }

    [System.Runtime.Serialization.DataMemberAttribute(IsRequired=true)]

    public bool IsPrivacyChanged

    {

    get

    {

    return this.IsPrivacyChangedField;

    }

    set

    {

    this.IsPrivacyChangedField = value;

    }

    }

    [System.Runtime.Serialization.DataMemberAttribute(IsRequired=true)]

    public bool IsValueChanged

    {

    get

    {

    return this.IsValueChangedField;

    }

    set

    {

    this.IsValueChangedField = value;

    }

    }

    [System.Runtime.Serialization.DataMemberAttribute(EmitDefaultValue=false)]

    public string Name

    {

    get

    {

    return this.NameField;

    }

    set

    {

    this.NameField = value;

    }

    }

    [System.Runtime.Serialization.DataMemberAttribute(IsRequired=true)]

    public microsoft.com.webservices.SharePointPortalServer.UserProfileService.Privacy Privacy

    {

    get

    {

    return this.PrivacyField;

    }

    set

    {

    this.PrivacyField = value;

    }

    }

    [System.Runtime.Serialization.DataMemberAttribute(EmitDefaultValue=false)]

    public microsoft.com.webservices.SharePointPortalServer.UserProfileService.ValueData[] Values

    {

    get

    {

    return this.ValuesField;

    }

    set

    {

    this.ValuesField = value;

    }

    }

    }

     

     

     

     

  • miércoles, 03 de junio de 2009 14:40GromRom Medallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuario
     

    I was able to reproduce as well.  The WSDL doesn't match the shape of the XML that is being returned from SharePoint.  The short-term fix is to change the generated proxy code to match the shape of what SharePoint is actually returning (versus what is exposed in its WSDL).  The actual shape of the message is:

    Notice that the IsPrivacyChanged and IsValueChanged elements need to appear first in the sequence.  For instance, you can change the generated WCF proxy type for the PropertyData class to look like the following:

    Code Snippet

    [System.Diagnostics.DebuggerStepThroughAttribute()]

    [System.CodeDom.Compiler.GeneratedCodeAttribute("System.Runtime.Serialization", "3.0.0.0")]

    [System.Runtime.Serialization.DataContractAttribute(Name="PropertyData", Namespace="http://microsoft.com/webservices/SharePointPortalServer/UserProfileService")]

    public partial class PropertyData : object, System.Runtime.Serialization.IExtensibleDataObject


    Hi kirke!

    I have replace my PropertyData class, by your code, but it not help me.

    Now I have other similar error:
    "Error in line 1 position 11015. 'Element' 'Privacy' from namespace 'http://microsoft.com/webservices/SharePointPortalServer/UserProfileService' is not expected. Expecting element 'Name | Group | Email | Title | Url | IsInWorkGroup'." 
  • sábado, 04 de julio de 2009 15:23Matthew McDermott, MVPMVPMedallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuario
     
    Same problem here. Anyone solve this?
    Matthew McDermott, MVP MOSS
  • sábado, 04 de julio de 2009 19:06Steve.CurranMVPMedallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuario
     

    Unfortunately, I was never successful at calling SharePoint web services by adding a service reference. You can add a regular .net 2.0 service reference by clicking on the "Advanced" button when adding a service reference and then clicking on "Add Web Reference"

    http://social.msdn.microsoft.com/Forums/en-US/sharepointdevelopment/thread/c22f1633-7d68-4dde-b935-37e5e2fe3162/

     


    certdev.com
  • sábado, 04 de julio de 2009 23:34Chakkaradeep Chandran Medallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuario
     Respuesta propuesta
    You need to add the SharePoint Service as normal ASMX service reference i.e; Web Reference from the Add Service Reference wizard and it should be always basicHttpBinding, otherwise it wont work.
    Regards,
    Chakkaradeep

    Twitter: http://twitter.com/chakkaradeep
    Blog: http://www.chakkaradeep.com
  • domingo, 05 de julio de 2009 12:50Matthew McDermott, MVPMVPMedallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuario
     
    Thanks for the response Steve. That option is not available in my Advanced dialog. Must have something to do with this being a Silverlight project.
    Matthew McDermott, MVP MOSS
  • domingo, 05 de julio de 2009 18:57Steve.CurranMVPMedallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuario
     Respuesta propuestaTiene código
    Ok Silverlight is different. Chakkaradeep was pointing the correct way. When you add a service reference just point to the ASMX url, like http://localhost/sitename/_vti_bin/lists.asmx and then open up your ServiceReferences.ClientConfig file in your project and make sure it is using basicHttpBinding like below

    <configuration>
        <system.serviceModel>
            <bindings>
                <basicHttpBinding>
                    <binding name="ListsSoap" maxBufferSize="2147483647"
                        maxReceivedMessageSize="2147483647">
                        <security mode="None" />
                    </binding>
                </basicHttpBinding>
            </bindings>
            <client>
                <endpoint address="http://localhost/_vti_bin/lists.asmx"
                    binding="basicHttpBinding" bindingConfiguration="ListsSoap"
                    contract="ListsClient.ListsSoap" name="ListsSoap" />
            </client>
        </system.serviceModel>
    </configuration>
    
    Then you can create the web service proxy like so and call the methods on it asynchronously:

    ListsSoap ls = new ListsSoap("ListsSoap", "http://localhost/sitename/_vti_bin/lists.asmx);
    

    certdev.com
  • martes, 07 de julio de 2009 12:41Matthew McDermott, MVPMVPMedallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuario
     
    Thanks guys. The issue appears t be with the UserProfileService. In your examples you are using Lists.asmx. I am calling UserProfileService.asmx. It appears that the XML result is malformed. It works in 2.0 applications but not 3.5 applications.

    I cannot mark your advice as an answer because it still does not work for the scenario that started the thread (though your advice may help others using the Lists.asmx or other SharePoint web service).

    I'll write my own WCF compliant service and use that.

    Thanks!

    Matthew
    Matthew McDermott, MVP MOSS