MSDN > 論壇首頁 > SharePoint - Development and Programming > Error calling sharepoint web services from .net 3.5 WCF client...
發問發問
 

提議的解答Error calling sharepoint web services from .net 3.5 WCF client...

  • 2008年7月16日 下午 08:52SteveCl 使用者勳章使用者勳章使用者勳章使用者勳章使用者勳章
     

     

     

    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???

所有回覆

  • 2008年7月16日 下午 08:53SteveCl 使用者勳章使用者勳章使用者勳章使用者勳章使用者勳章
     
    i should mention that the same code in .net 2.0 works fine....

     

  • 2008年7月18日 下午 04:34charoldson 使用者勳章使用者勳章使用者勳章使用者勳章使用者勳章
     

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

  • 2008年7月21日 下午 08:01kirke 使用者勳章使用者勳章使用者勳章使用者勳章使用者勳章
     

    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;

    }

    }

    }

     

     

     

     

  • 2009年6月3日 下午 02:40GromRom 使用者勳章使用者勳章使用者勳章使用者勳章使用者勳章
     

    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'." 
  • 2009年7月4日 下午 03:23Matthew McDermott, MVPMVP使用者勳章使用者勳章使用者勳章使用者勳章使用者勳章
     
    Same problem here. Anyone solve this?
    Matthew McDermott, MVP MOSS
  • 2009年7月4日 下午 07:06Steve.CurranMVP使用者勳章使用者勳章使用者勳章使用者勳章使用者勳章
     

    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
  • 2009年7月4日 下午 11:34Chakkaradeep Chandran 使用者勳章使用者勳章使用者勳章使用者勳章使用者勳章
     提議的解答
    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
  • 2009年7月5日 下午 12:50Matthew McDermott, MVPMVP使用者勳章使用者勳章使用者勳章使用者勳章使用者勳章
     
    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
  • 2009年7月5日 下午 06:57Steve.CurranMVP使用者勳章使用者勳章使用者勳章使用者勳章使用者勳章
     提議的解答包含代碼
    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
  • 2009年7月7日 下午 12:41Matthew McDermott, MVPMVP使用者勳章使用者勳章使用者勳章使用者勳章使用者勳章
     
    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