C# 使用Azure应用程序服务托管的WCF服务中出错:HTTP错误405.0-不允许使用方法

C# 使用Azure应用程序服务托管的WCF服务中出错:HTTP错误405.0-不允许使用方法,c#,web-services,wcf,xamarin.forms,azure-app-service-envrmnt,C#,Web Services,Wcf,Xamarin.forms,Azure App Service Envrmnt,好的,这里的WCF完全是新手,所以请对我耐心点 我有一个发布在Azure app service上的WCF web服务,以及一个必须连接到该服务的Xamarin.forms应用程序 我创建了WCF服务,起初我尝试自行托管它,并使用visual studio 2017“添加服务”在我的xamarin应用程序上创建了客户端。因此,它添加了Reference.cs文件,我创建了代理类和接口来连接到服务 我在从手机连接到该服务时遇到问题,因此我在Azure app service上发布了该服务(毕竟是免

好的,这里的WCF完全是新手,所以请对我耐心点

我有一个发布在Azure app service上的WCF web服务,以及一个必须连接到该服务的Xamarin.forms应用程序

我创建了WCF服务,起初我尝试自行托管它,并使用visual studio 2017“添加服务”在我的xamarin应用程序上创建了客户端。因此,它添加了
Reference.cs
文件,我创建了代理类和接口来连接到服务

我在从手机连接到该服务时遇到问题,因此我在Azure app service上发布了该服务(毕竟是免费的),启用了Azure日志,修改了
NLog.config
文件以登录到跟踪,只修改了我手机应用中的URL,现在每当我尝试从手机连接到该服务时,该服务都会抛出此错误:

HTTP错误405.0-不允许使用方法。由于使用了无效的方法(HTTP谓词),因此无法显示您正在查找的页面。

我正在Visual Studio的云资源管理器的
LogFiles\DetailedErrors
文件夹中读取错误

老实说,我对HTTP几乎一无所知,但我知道我还没有在服务中编写HTTP。我想WCF在某个时刻、某个地方使用了一个不好的动词,但我怎么知道在哪里更改它,甚至如何检查它呢?我只是做了一个接口,一个类,然后调用这个类上的方法。。。不知道在哪里找职位或得到

无论如何,我甚至不确定我应该在这里发布什么代码,但我已经阅读了很多关于这方面的问题,所以这里有一些:

服务等级

public class MJRFFrasCdadesService : IMJRFFrasCdadesService, IDisposable
{
    private Users.UsersClass _Users = new Users.UsersClass();
    private static NLog.Logger _Logger = NLog.LogManager.GetCurrentClassLogger();
    private bool _Disposed;

    public static event EventHandler<ConnectionEventArgs> ConnectionEvent;
    public static event EventHandler<ConnectionEventArgs> DisconnectionEvent;

    public string Ping()
    {
        return "Ok";
    }

    public async Task<string> GoogleLoginAsync(string email)
    {
        NLog.LogManager.Configuration.Variables["email"] = "";
        _Logger.Info("{1}{2}{1}           Comienza google login con email: {0}{1}{2}",
            email,
            Environment.NewLine,
            "-----------------------------------*******************************************");

        var driveHandler = await _Users.NewUserAsync(email);

        try
        {
            var init = await driveHandler.InitDriveAsync(email);
            _Logger.Info("InitDriveAsync finalizado con resultado: {0}", init);
            if (!init || !driveHandler.LoginOK)
            {
                _Logger.Info("Devolviendo mensaje de error: {0}", driveHandler.MsgError);
                return driveHandler.MsgError;
            }
            _Logger.Info("Login ok, devolviendo \"Ok\"");
            return "Ok";
        }
        catch (Exception e)
        {
            _Logger.Error(e);
            return e.ExceptionErrorMessage();
        }
    }

    public async Task<string> UploadFileAsync(byte[] fileBytes, string fileName, string email)
    {
        _Logger.Info("Comienza subida de fichero con nombre {0}", fileName);

        var driveHandler = await _Users.GetUserDriveHandler(email);
        if (driveHandler == null)
        {
            _Logger.Info("No logueado. Devolviendo \"User not logged\"");
            return "User not logged";
        }

        try
        {
            if (!driveHandler.LoginOK)
            {
                _Logger.Info("No logueado. Devolviendo \"Not logged\"");
                return "Not logged";
            }

            var result = await driveHandler.UploadImageAsync(fileBytes, fileName);
            _Logger.Info("Proceso de subida terminado. Resultado: {0}", result);
            if (!result)
            {
                _Logger.Info("Devolviendo mensaje de error: {0}", driveHandler.MsgError);
                return driveHandler.MsgError;
            }
            _Logger.Info("Subida ok, devolviendo \"Ok\"");
            return "OK";
        }
        catch (Exception e)
        {
            _Logger.Error(e);
            return e.ExceptionErrorMessage();
        }
    }

    public void Dispose()
    {
        if (!_Disposed)
        {
            _Users.Dispose();
        }
        _Disposed = true;
    }

    public void FirstMethod()
    {
        if (ConnectionEvent != null)
        {
            string m = "Alguien se ha conectado";
            ConnectionEvent(null, new ConnectionEventArgs()
            {
                Message = m
            });
            _Logger.Info(m);
        }
    }

    public void LastMethod()
    {
        if (DisconnectionEvent != null)
        {
            string m = "Alguien se ha desconectado";
            DisconnectionEvent(null, new ConnectionEventArgs()
            {
                Message = m
            });
            _Logger.Info(m);
        }
    }
}
这是一个不同的错误(我想至少这是一个进步)。正如您所看到的,
GoogleLoginAsync
方法正在抛出该异常,但现在抛出该异常的是我的app方法,而不是服务:
servicerence1.mjrfrascdedesserviceclient
是Visual Studio在我仍然自托管服务时添加服务引用时生成的类

我想我将删除该引用,向azure中托管的服务添加一个新引用,然后再次测试所有这些


Edit2:

是的,它解决了这个问题,但现在我有一个:

Error in deserializing body of request message for operation 'GoogleLogin'. OperationFormatter encountered an invalid Message body. Expected to find node type 'Element' with name 'GoogleLogin' and namespace 'http://tempuri.org/'. Found node type 'Element' with name 'GoogleLoginAsync' and namespace 'http://tempuri.org/' ;

            Trace: 
at (wrapper managed-to-native) System.Object.__icall_wrapper_mono_remoting_wrapper(intptr,intptr)
at (wrapper remoting-invoke) ServiceReference2.IMJRFFrasCdadesService.GoogleLoginAsync(string)
at ServiceReference2.MJRFFrasCdadesServiceClient.GoogleLoginAsync (System.String email) [0x00006] in <e1f3df4dfbf340f09d2768d7fbc33427>:0 
at MJRFFacturasComunidades.Model.WebService.WebServiceClass+<LogEmail>d__6.MoveNext () [0x00023] in <e1f3df4dfbf340f09d2768d7fbc33427>:0  ;
对操作“GoogleLogin”的请求消息体进行反序列化时出错。OperationFormatter遇到无效的消息正文。应找到名为“GoogleLogin”和命名空间为“Element”的节点类型“Element”http://tempuri.org/'. 找到名为“GoogleLoginAsync”且命名空间为“1”的节点类型“Element”http://tempuri.org/' ; 跟踪: at(wrapper managed to native)System.Object.\uIcall\uwrapper\uMono\uRemoting\uwrapper(intptr,intptr) at(包装器远程调用)ServiceReference2.imjrfrascdadesservice.GoogleLoginAsync(字符串) 在0中的ServiceReference2.mjrffrascdadeserviceclient.GoogleLoginAsync(System.String电子邮件)[0x00006]处 在mjrfacturascomunidades.Model.WebService.WebServiceClass+d_u6.MoveNext()[0x00023]中:0;
xD一个接一个。好的,我不确定我是否应该在同一个问题中继续问这个问题,因为原来的问题已经解决了,所以我接受了答案,继续尝试或开始一个新问题。

以下是一些你可以尝试的事情

  • 检查服务是否正在运行(浏览.svc文件就足够了)
  • 检查服务契约是否相同,这将是WSDL文件(检查所有方法是否相同(更重要的是,如果您的方法存在)

  • 您的服务未运行,很可能是因为您的回答,我编辑了问题,我也解决了原始问题,但它不断给我带来更多问题。我接受您的回答,请您阅读编辑内容,以备您的帮助:)
    <?xml version="1.0" encoding="utf-8"?>
    <configuration>
    
      <appSettings>
        <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
      </appSettings>
      <system.web>
        <compilation debug="true" targetFramework="4.7.1" />
        <httpRuntime targetFramework="4.7.1"/>
      </system.web>
      <system.serviceModel>
        <behaviors>
          <serviceBehaviors>
            <behavior>
              <!-- Para evitar revelar información de los metadatos, establezca los valores siguientes en false antes de la implementación  -->
              <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
              <!-- Para recibir detalles de las excepciones en los fallos, con el fin de poder realizar la depuración, establezca el valor         siguiente en true. Para no revelar información sobre las excepciones, establézcalo en false antes de la implementación -->
              <serviceDebug includeExceptionDetailInFaults="true"/>
            </behavior>
          </serviceBehaviors>
        </behaviors>
        <protocolMapping>
            <add binding="basicHttpsBinding" scheme="https" />
        </protocolMapping>    
        <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
      </system.serviceModel>
      <system.webServer>
        <modules runAllManagedModulesForAllRequests="true"/>
        <!--
            Para examinar el directorio raíz de la aplicación web durante la depuración, establezca el valor siguiente en true.
            Establézcalo en false antes de la implementación para evitar revelar información sobre la carpeta de aplicación web.
          -->
        <directoryBrowse enabled="true"/>
      </system.webServer>
    
    </configuration>
    
                Error: 
    There was an error on processing web request: Status code 405(MethodNotAllowed): Method Not Allowed ;
    
                Trace: 
    at (wrapper managed-to-native) System.Object.__icall_wrapper_mono_remoting_wrapper(intptr,intptr)
    at (wrapper remoting-invoke) ServiceReference1.IMJRFFrasCdadesService.GoogleLoginAsync(string)
    at ServiceReference1.MJRFFrasCdadesServiceClient.GoogleLoginAsync (System.String email) [0x00006] in <61e2d5b4688b450c9b2865fbef0c9da1>:0 
    at MJRFFacturasComunidades.Model.WebService.WebServiceClass+<LogEmail>d__6.MoveNext () [0x00023] in <61e2d5b4688b450c9b2865fbef0c9da1>:0 ;
    
    Error in deserializing body of request message for operation 'GoogleLogin'. OperationFormatter encountered an invalid Message body. Expected to find node type 'Element' with name 'GoogleLogin' and namespace 'http://tempuri.org/'. Found node type 'Element' with name 'GoogleLoginAsync' and namespace 'http://tempuri.org/' ;
    
                Trace: 
    at (wrapper managed-to-native) System.Object.__icall_wrapper_mono_remoting_wrapper(intptr,intptr)
    at (wrapper remoting-invoke) ServiceReference2.IMJRFFrasCdadesService.GoogleLoginAsync(string)
    at ServiceReference2.MJRFFrasCdadesServiceClient.GoogleLoginAsync (System.String email) [0x00006] in <e1f3df4dfbf340f09d2768d7fbc33427>:0 
    at MJRFFacturasComunidades.Model.WebService.WebServiceClass+<LogEmail>d__6.MoveNext () [0x00023] in <e1f3df4dfbf340f09d2768d7fbc33427>:0  ;