android 调用c wcf服务,如何使用命名管道从c调用WCF方法?

更新:

通过协议

here,我无法弄清楚未知的信封记录.我在网上找不到任何例子.

原版的:

我有以下WCF服务

static void Main(string[] args)

{

var inst = new PlusFiver();

using (ServiceHost host = new ServiceHost(inst,new Uri[] { new Uri("net.pipe://localhost") }))

{

host.AddServiceEndpoint(typeof(IPlusFive),new NetNamedPipeBinding(NetNamedPipeSecurityMode.None),"PipePlusFive");

host.Open();

Console.WriteLine("Service is Available. Press enter to exit.");

Console.ReadLine();

host.Close();

}

}

[ServiceContract]

public interface IPlusFive

{

[OperationContract]

int PlusFive(int value);

}

[ServiceBehavior(InstanceContextMode = InstanceContextMode.Single)]

public class PlusFiver : IPlusFive

{

public int PlusFive(int value)

{

Console.WriteLine("Adding 5 to " + value);

return value + 5;

}

}

我输出添加5行,所以我知道服务器是否处理了

请求与否.

我有一个.NET客户端,我曾经测试这一切,一切正常工作

预期.

现在我想为这个做一个非托管的C客户端.

我想出了如何得到管道的名称,并写信给它.

我从here下载了协议

我可以写信给管道,但我看不懂.每当我尝试读取它,我得到一个ERROR_BROKEN_PIPE 109(0x6D)管道已经结束.错误.如果我用写入替换读取,则写入是成功的,所以我不认为管道是封闭的,至少直到我尝试读取.

这是我如何连接到管道.

HANDLE OpenPipe(OLECHAR* bstrGuid)

{

wstring pipeName = L"\\\\.\\pipe\\";

wstring strGuid = bstrGuid;

pipeName.append(strGuid.substr(1,36));

wcout << "Pipe Name " << endl;

wcout << pipeName.c_str() << endl;

HANDLE hPipe = CreateFile(pipeName.c_str(),GENERIC_WRITE | GENERIC_READ,FILE_SHARE_WRITE | FILE_SHARE_READ,NULL,OPEN_EXISTING,NULL);

if(hPipe == INVALID_HANDLE_VALUE)

{

wcout << "Failed to create pipe" << endl;

system("pause");

return NULL;

}

return hPipe;

}

这是我正在创建我发送的第一条消息

std::list GetFirstMessage()

{

std::list message;

message.push_back(0x00);// version record

message.push_back(0x01);// major version

message.push_back(0x00);// minor version

message.push_back(0x01);// mode record

message.push_back(0x01);// singleton-unsized mode

message.push_back(0x02);// via record

wstring url = L"net.pipe://localhost/PipePlusFive";

message.push_back(url.length());// via length

for(int x= 0;x

{

message.push_back(url[x]); // via

}

message.push_back(0x03);

message.push_back(0x08);

return message;

}

这是我如何写文件.

int WriteMessage(HANDLE hPipe,LPVOID message,int size)

{

DWORD bytesWritten;

BOOL bWrite = WriteFile(hPipe,&message,size,&bytesWritten,NULL);

wcout << "Bytes Written: " << bytesWritten << endl;

if(bWrite == false)

{

wcout << "fail"<

CloseHandle(hPipe);

system("pause");

return 1;

}

return 0;

}

list full_message = GetFirstMessage();

int result = WriteMessage(hPipe,&full_message,full_message.size());

if (result == 1)

{ return 1;}

这是我如何写最后的消息

wchar_t message = 12;

result = WriteMessage(hPipe,1);

if (result == 1)

{ return 1;}

这是我如何读取响应

char buffer[10];

DWORD bytesRead;

BOOL bRead = ReadFile(hPipe,buffer,1,&bytesRead,NULL);

if(bRead == false)

{

wcout << "fail read"<

wcout << "error: " << GetLastError() << endl;

CloseHandle(hPipe);

system("pause");

return 1;

}

我是新来的c,所以我不知道我是不是正确地遵循协议,或者是以我这样做的方式犯了一个愚蠢的错误?

更新:

问题是我正在将命名地址写入命名管道而不是列表的内容.我已经解决了,我现在可以阅读前言Ack记录.现在我必须弄清楚下一部分协议需要发送什么.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值