Xamarin Android应用程序调用wcf服务System.Xml.XmlException:根级别的数据无效。第2行,位置1
我有一个Xamarin Android应用程序,我正在使用一个WCF服务,我正在调用它,它是由其他人编写的。我得到的错误是:Xamarin Android应用程序调用wcf服务System.Xml.XmlException:根级别的数据无效。第2行,位置1,wcf,xamarin.android,Wcf,Xamarin.android,我有一个Xamarin Android应用程序,我正在使用一个WCF服务,我正在调用它,它是由其他人编写的。我得到的错误是: {System.Xml.XmlException: Data at the root level is invalid. Line 2, position 1. at (wrapper managed-to-native) System.Object:__icall_wrapper_mono_delegate_end_invoke (object,intptr)
{System.Xml.XmlException: Data at the root level is invalid. Line 2, position 1.
at (wrapper managed-to-native) System.Object:__icall_wrapper_mono_delegate_end_invoke (object,intptr)
at (wrapper delegate-end-invoke) <Module>:end_invoke_object__this___object[]&_IAsyncResult (object[]&,System.IAsyncResult)
at System.ServiceModel.MonoInternal.ClientRuntimeChannel.EndProcess (System.Reflection.MethodBase method, System.String operationName, System.Object[] parameters, System.IAsyncResult result) [0x00025] in /Users/builder/data/lanes/3511/77cb8568/source/mono/mcs/class/System.ServiceModel/System.ServiceModel/ClientRuntimeChannel.cs:460
at System.ServiceModel.ClientBase`1+ChannelBase`1[TChannel,T].EndInvoke (System.String methodName, System.Object[] args, System.IAsyncResult result) [0x0003c] in /Users/builder/data/lanes/3511/77cb8568/source/mono/mcs/class/System.ServiceModel/System.ServiceModel/ClientBase.cs:404
at DataServiceClient+DataServiceClientChannel.EndGetUsers (System.IAsyncResult result) [0x00008] in C:\Projects\MyApp\MyApp\MyAppMobileProxy.cs:5021
at DataServiceClient.IDataService.EndGetUsers (System.IAsyncResult result) [0x00001] in C:\Projects\MyApp\MyApp\MyAppMobileProxy.cs:3926
at DataServiceClient.OnEndGetUsers (System.IAsyncResult result) [0x00001] in C:\Projects\MyApp\MyApp\MyAppMobileProxy.cs:3937
at System.ServiceModel.ClientBase`1+<InvokeAsync>c__AnonStorey0[TChannel].<>m__0 (System.IAsyncResult ar) [0x00006] in /Users/builder/data/lanes/3511/77cb8568/source/mono/mcs/class/System.ServiceModel/System.ServiceModel/ClientBase.cs:242 }
在代理类中,这是引发错误的地方:
public mycompany.net.services.thisapp._2016._01.User[] EndGetUsers(System.IAsyncResult result)
{
object[] _args = new object[0];
mycompany.net.services.thisApp._2016._01.User[] _result = ((mycompany.net.services.thisApp._2016._01.User[])(base.EndInvoke("GetUsers", _args, result)));
return _result;
}
wsdl:
<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:wsaw="http://www.w3.org/2006/05/addressing/wsdl"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://mycompany.net/services/thisapp/2016/01"
xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:wsam="http://www.w3.org/2007/05/addressing/metadata"
xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/"
xmlns:msc="http://schemas.microsoft.com/ws/2005/12/wsdl/contract" xmlns:wsap="http://schemas.xmlsoap.org/ws/2004/08/addressing/policy"
xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:wsa10="http://www.w3.org/2005/08/addressing" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:wsx="http://schemas.xmlsoap.org/ws/2004/09/mex" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" targetNamespace="http://mycompany.net/services/thisapp/2016/01" name="DataService">
Web.Config文件
<?xml version="1.0"?>
<configuration>
<connectionStrings>
<add
name="MyDatabase"
connectionString="Data Source=MyServer\SQL2012;Initial Catalog=MyDatabase;User ID=****;Password=******"
providerName="System.Data.SqlClient;"/>
</connectionStrings>
<appSettings>
<add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
</appSettings>
<system.web>
<compilation debug="true" targetFramework="4.5.2" />
<httpRuntime targetFramework="4.5.2"/>
</system.web>
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding
name="wsHttpMtomStandardBinding"
maxReceivedMessageSize ="2000000"
messageEncoding="Mtom">
<readerQuotas maxArrayLength="2000000"/>
<reliableSession
enabled="false"
ordered="false"
inactivityTimeout="00:10:00"/>
<security mode="None" >
<transport clientCredentialType="None" proxyCredentialType="None" realm="" />
</security>
</binding>
<binding
name="wsHttpMtomSSLBinding"
maxReceivedMessageSize ="2000000"
messageEncoding="Mtom">
<readerQuotas maxArrayLength="2000000"/>
<reliableSession
enabled="false"
ordered="false"
inactivityTimeout="00:10:00"/>
<security mode="Transport" >
<transport clientCredentialType="None" proxyCredentialType="None" realm="" />
</security>
</binding>
</wsHttpBinding>
<basicHttpBinding>
<binding
name="basicHttpStandardBinding"
maxReceivedMessageSize ="2000000"
messageEncoding="Mtom">
<security mode="Transport">
<transport clientCredentialType="None" proxyCredentialType="None" realm="" />
</security>
</binding>
</basicHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="NormalBehavior">
<!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="true" />
<!-- To avoid disclosing metadata information, set the values below to false before deployment -->
<serviceMetadata httpGetEnabled="true" />
<serviceThrottling maxConcurrentCalls="32" maxConcurrentInstances="32" />
</behavior>
<behavior name="SecureBehavior">
<!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="true" />
<!-- To avoid disclosing metadata information, set the values below to false before deployment -->
<serviceMetadata httpsGetEnabled="true"/>
<serviceThrottling maxConcurrentCalls="32" maxConcurrentInstances="32" />
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service
name="MyApp.Services.DataService"
behaviorConfiguration="SecureBehavior">
<endpoint address="mex"
binding="mexHttpsBinding"
contract="IMetadataExchange"/>
<endpoint
address=""
binding="basicHttpBinding"
contract="MyApp.Contracts.IDataService"
bindingConfiguration="basicHttpStandardBinding" />
</service>
</services>
<protocolMapping>
<add binding="basicHttpsBinding" scheme="https" />
<add binding="basicHttpBinding" scheme="http" />
<add binding="wsHttpBinding" scheme="https"/>
<add binding="wsHttpBinding" scheme="http"/>
</protocolMapping>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
<!--
To browse web app root directory during debugging, set the value below to true.
Set to false before deployment to avoid disclosing web app folder information.
-->
<directoryBrowse enabled="true"/>
</system.webServer>
</configuration>
<?xml version="1.0"?>
<configuration>
<connectionStrings>
<add
name="MyDatabase"
connectionString="Data Source=MyServer\SQL2012;Initial Catalog=MyDatabase;User ID=****;Password=******"
providerName="System.Data.SqlClient;"/>
</connectionStrings>
<appSettings>
<add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
</appSettings>
<system.web>
<compilation debug="true" targetFramework="4.5.2" />
<httpRuntime targetFramework="4.5.2"/>
</system.web>
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding
name="wsHttpMtomStandardBinding"
maxReceivedMessageSize ="2000000"
messageEncoding="Mtom">
<readerQuotas maxArrayLength="2000000"/>
<reliableSession
enabled="false"
ordered="false"
inactivityTimeout="00:10:00"/>
<security mode="None" >
<transport clientCredentialType="None" proxyCredentialType="None" realm="" />
</security>
</binding>
<binding
name="wsHttpMtomSSLBinding"
maxReceivedMessageSize ="2000000"
messageEncoding="Mtom">
<readerQuotas maxArrayLength="2000000"/>
<reliableSession
enabled="false"
ordered="false"
inactivityTimeout="00:10:00"/>
<security mode="Transport" >
<transport clientCredentialType="None" proxyCredentialType="None" realm="" />
</security>
</binding>
</wsHttpBinding>
<basicHttpBinding>
<binding
name="basicHttpStandardBinding"
maxReceivedMessageSize ="2000000"
messageEncoding="Mtom">
<security mode="Transport">
<transport clientCredentialType="None" proxyCredentialType="None" realm="" />
</security>
</binding>
</basicHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="NormalBehavior">
<!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="true" />
<!-- To avoid disclosing metadata information, set the values below to false before deployment -->
<serviceMetadata httpGetEnabled="true" />
<serviceThrottling maxConcurrentCalls="32" maxConcurrentInstances="32" />
</behavior>
<behavior name="SecureBehavior">
<!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="true" />
<!-- To avoid disclosing metadata information, set the values below to false before deployment -->
<serviceMetadata httpsGetEnabled="true"/>
<serviceThrottling maxConcurrentCalls="32" maxConcurrentInstances="32" />
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service
name="MyApp.Services.DataService"
behaviorConfiguration="SecureBehavior">
<endpoint address="mex"
binding="mexHttpsBinding"
contract="IMetadataExchange"/>
<endpoint
address=""
binding="basicHttpBinding"
contract="MyApp.Contracts.IDataService"
bindingConfiguration="basicHttpStandardBinding" />
</service>
</services>
<protocolMapping>
<add binding="basicHttpsBinding" scheme="https" />
<add binding="basicHttpBinding" scheme="http" />
<add binding="wsHttpBinding" scheme="https"/>
<add binding="wsHttpBinding" scheme="http"/>
</protocolMapping>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
<!--
To browse web app root directory during debugging, set the value below to true.
Set to false before deployment to avoid disclosing web app folder information.
-->
<directoryBrowse enabled="true"/>
</system.webServer>
</configuration>