SignalR IOS 客户端、Web 套接字传输无法从服务器调用该方法 [英] SignalR IOS Client, Web Socket transport cannot invoke the method from server

查看:74
本文介绍了SignalR IOS 客户端、Web 套接字传输无法从服务器调用该方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 SignalR-ObjC 客户端来提供我的 IOS 应用程序和 .Net 服务器之间的通信.

I m using SignalR-ObjC Client to provide communication between my IOS application and .Net server.

我可以从自托管跨域服务器连接 longpulling 和调用方法,没有任何错误.但是由于我的应用程序需要,我必须使用 WebSocket.我有一个单身经理,如:

I can connect with longpulling and invoke methods from self-host cross domain server without any error. But because of my applications needs i have to use WebSocket. I have a Singleton Manager like :

@implementation SignalRManager
static int reconnectingTry;
+ (id)sharedManager {
    static SignalRManager *sharedHttpManager = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        sharedHttpManager = [[self alloc] init];
        sharedHttpManager.hubConnection = [SRHubConnection connectionWithURL:@"http://xxx:8080/signalr"];
        sharedHttpManager.proxy = [sharedHttpManager.hubConnection createHubProxy:@"myhub"];
    });

    return sharedHttpManager;
}
+(SRHubProxy *)proxy
{
    return [[SignalRManager sharedManager] proxy];
}

+(SRHubConnection *)connection
{
    return [[SignalRManager sharedManager] hubConnection];
}

+(void)start
{
    SRWebSocketTransport *transport = [[SRWebSocketTransport alloc] init];

    [[SignalRManager connection] start:transport];

}
+(void)stop
{
    [[SignalRManager connection] stop];
}

我正在调用:

 [[SignalRManager proxy] invoke:@"Hello" withArgs:[NSArray array]];

我建立了连接,服务器可以调用客户端方法,但是当我尝试从客户端到服务器调用方法时,出现请求失败:错误请求(400)"错误.

i establish connection and server can invoke client method but when i try invoke method from client to server the "Request failed:bad request(400)" error occur.

推荐答案

似乎是 SRWebSocketTransport 中的协议(SRClientTransportInterface)实现的问题.

seems to be a problem with the protocol (SRClientTransportInterface) implementation in SRWebSocketTransport.

实际上是:

- (void)send:(id <SRConnectionInterface>)connection data:(NSString *)data completionHandler:(void (^)(id response, NSError *error))block;

而且必须

- (void)send:(id <SRConnectionInterface>)connection data:(NSString *)data connectionData:(NSString *)connectionData completionHandler:(void (^)(id response, NSError *error))block; 

像子类没有那个实现调用超类(SRHttpBasedTransport)方法,因此你得到请求失败:错误请求(400)"(是另一个http请求而不是websocket).

Like subclass does not have that implementation is calling superclass (SRHttpBasedTransport) method and for that reason you got "Request failed:bad request(400)" (is another http request and not websocket).

要修复只需在 Pods 项目中打开文件 SRWebSocketTransport.m 并更改实现,如下所示:

To fix just open the file SRWebSocketTransport.m in your Pods project and change the implementation, something like this:

- (void)send:(id<SRConnectionInterface>)connection data:(NSString *)data connectionData:(NSString *)connectionData completionHandler:(void (^)(id response, NSError *error))block {
    [_webSocket send:data];

    if(block) {
        block(nil,nil);
    }
}

希望对您有所帮助.

pd:只是检查 github 似乎已在 feature-2.0.0.beta1 分支中修复

pd: just checking github seems to be fixed in feature-2.0.0.beta1 branch

这篇关于SignalR IOS 客户端、Web 套接字传输无法从服务器调用该方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆