XamarinAndroid 中的错误“System.Net.Sockets.SocketException:System.Net.Sockets.SocketAsyncResult.CheckIfThrowDelayedException 处的连接被拒绝”

问题描述 投票:0回答:1

我创建了一个 WCF 应用程序,它有 3 个方法来返回一些用户数据进行测试。我测试过没有问题。 我在 Xamarin 中添加了 Web 参考,但是当我想使用该方法时,它出现错误异常。

WCF web.config

    <?xml version="1.0" encoding="utf-8"?>
<configuration>
    <configSections>
        <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
        <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
    </configSections>
    <appSettings>
        <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
    </appSettings>
    <system.web>
        <compilation debug="true" targetFramework="4.8" />
        <httpRuntime targetFramework="4.8" />
    </system.web>
    <system.serviceModel>
        <behaviors>
            <serviceBehaviors>
                <behavior name="MyBehavior">
                    <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
                    <serviceDebug includeExceptionDetailInFaults="false" />
                </behavior>
            </serviceBehaviors>
            <endpointBehaviors>
                <behavior name="EndpointBehavior">
                    
                </behavior>
            </endpointBehaviors>
        </behaviors>
        <services>
            <service name="MyStoreService.MyStoreService"
               behaviorConfiguration="MyBehavior">
                <endpoint
                    address=""
                    binding="wsHttpBinding"
                    bindingConfiguration="MyBinding"
                    behaviorConfiguration="EndpointBehavior"
                    contract="MyStoreService.IMyStoreService"
                    name="MyStoreService"/>
                <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>

                <host>
                    <baseAddresses>
                        <add baseAddress="http://localhost:58514/MyStoreService.svc" />
                    </baseAddresses>
                </host>
            </service>

        </services>

        <bindings>
            <wsHttpBinding>
                <binding name="MyBinding" >

                </binding>
            </wsHttpBinding>
        </bindings>
        <protocolMapping>
            <add binding="basicHttpsBinding" scheme="https" />
        </protocolMapping>
        <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
    </system.serviceModel>
    <system.webServer>
        <modules runAllManagedModulesForAllRequests="true" />


        <directoryBrowse enabled="true" />
    </system.webServer>
    <entityFramework>
        <providers>
            <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
        </providers>
    </entityFramework>
    <connectionStrings>
        <add name="ServiceConnection" connectionString="Data Source=.;Initial Catalog=StoreDb;Integrated Security=true;" providerName="System.Data.SqlClient"/>
    </connectionStrings>
</configuration>

这是我在 Xamarin android 中使用 C# 的代码

localhost.MyStoreService service = new MyStoreService();
            var user = service.UserGetById(1, true);


            label.Text = user.FName;

这就是错误异常

{System.Net.WebException: Error: ConnectFailure (Connection refused) ---> System.Net.Sockets.SocketException: Connection refused  at System.Net.Sockets.SocketAsyncResult.CheckIfThrowDelayedException () [0x00014] in /Users/builder/jenkins/workspace/archive-mono/2020-02/android/release/mcs/class/System/System.Net.Sockets/SocketAsyncResult.cs:127   at System.Net.Sockets.Socket.EndConnect (System.IAsyncResult asyncResult) [0x0002c] in /Users/builder/jenkins/workspace/archive-mono/2020-02/android/release/mcs/class/System/System.Net.Sockets/Socket.cs:1214   at System.Net.WebConnection+<>c.<Connect>b__16_1 (System.IAsyncResult asyncResult) [0x00000] in /Users/builder/jenkins/workspace/archive-mono/2020-02/android/release/mcs/class/System/System.Net/WebConnection.cs:182   at System.Threading.Tasks.TaskFactory`1[TResult].FromAsyncCoreLogic (System.IAsyncResult iar, System.Func`2[T,TResult] endFunction, System.Action`1[T] endAction, System.Threading.Tasks.Task`1[TResult] promise, System.Boolean requiresSynchronization) [0x00019] in /Users/builder/jenkins/workspace/archive-mono/2020-02/android/release/external/corert/src/System.Private.CoreLib/src/System/Threading/Tasks/FutureFactory.cs:538 --- End of stack trace from previous location where exception was thrown ---  at System.Net.WebConnection.Connect (System.Net.WebOperation operation, System.Threading.CancellationToken cancellationToken) [0x00197] in /Users/builder/jenkins/workspace/archive-mono/2020-02/android/release/mcs/class/System/System.Net/WebConnection.cs:180    --- End of inner exception stack trace ---  at System.Net.WebConnection.Connect (System.Net.WebOperation operation, System.Threading.CancellationToken cancellationToken) [0x0025d] in /Users/builder/jenkins/workspace/archive-mono/2020-02/android/release/mcs/class/System/System.Net/WebConnection.cs:202   at System.Net.WebConnection.InitConnection (System.Net.WebOperation operation, System.Threading.CancellationToken cancellationToken) [0x000cc] in /Users/builder/jenkins/workspace/archive-mono/2020-02/android/release/mcs/class/System/System.Net/WebConnection.cs:273   at System.Net.WebOperation.Run () [0x00052] in /Users/builder/jenkins/workspace/archive-mono/2020-02/android/release/mcs/class/System/System.Net/WebOperation.cs:268   at System.Net.WebCompletionSource`1[T].WaitForCompletion () [0x0008e] in /Users/builder/jenkins/workspace/archive-mono/2020-02/android/release/mcs/class/System/System.Net/WebCompletionSource.cs:111   at System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke (System.String method_name, System.Object[] parameters) [0x000a7] in /Users/builder/jenkins/workspace/archive-mono/2020-02/android/release/mcs/class/System.Web.Services/System.Web.Services.Protocols/SoapHttpClientProtocol.cs:364   at MyStoreApplication.localhost.MyStoreService.UserGetById (System.Int64 UId, System.Boolean UIdSpecified) [0x00001] in F:\StoreProject\MyStoreApplication\MyStoreApplication\Web References\localhost\Reference.cs:227   at (wrapper remoting-invoke-with-check) MyStoreApplication.localhost.MyStoreService.UserGetById(long,bool)  at MyStoreApplication.MainActivity.GetData () [0x00007] in F:\StoreProject\MyStoreApplication\MyStoreApplication\MainActivity.cs:147   at MyStoreApplication.MainActivity.OnCreate (Android.OS.Bundle savedInstanceState) [0x000aa] in F:\StoreProject\MyStoreApplication\MyStoreApplication\MainActivity.cs:47   at Android.App.Activity.n_OnCreate_Landroid_os_Bundle_ (System.IntPtr jnienv, System.IntPtr native__this, System.IntPtr native_savedInstanceState) [0x00010] in /Users/builder/azdo/_work/1/s/xamarin-android/src/Mono.Android/obj/Release/monoandroid10/android-30/mcw/Android.App.Activity.cs:2986   at (wrapper dynamic-method) Android.Runtime.DynamicMethodNameCounter.3(intptr,intptr,intptr)}

我是 wcf 和 xamarin 的新手。请帮我解决问题吗?

这是图片可能有帮助 [1]:https://s21.picofile.com/file/8444961626/Error.png

wcf xamarin
1个回答
0
投票

兄弟你是怎么解决的? 我需要帮助你

© www.soinside.com 2019 - 2024. All rights reserved.