Microsoft Developer Network > 포럼 홈 > 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일 수요일 오후 8: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일 수요일 오후 8:53SteveCl 사용자 메달사용자 메달사용자 메달사용자 메달사용자 메달
     
    i should mention that the same code in .net 2.0 works fine....

     

  • 2008년 7월 18일 금요일 오후 4:34charoldson 사용자 메달사용자 메달사용자 메달사용자 메달사용자 메달
     

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

  • 2008년 7월 21일 월요일 오후 8: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일 수요일 오후 2: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일 토요일 오후 3:23Matthew McDermott, MVPMVP사용자 메달사용자 메달사용자 메달사용자 메달사용자 메달
     
    Same problem here. Anyone solve this?
    Matthew McDermott, MVP MOSS
  • 2009년 7월 4일 토요일 오후 7: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일 일요일 오후 6: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