【发布时间】:2013-12-21 09:54:13
【问题描述】:
我有一个查询数据库并返回这些查询结果的网络服务。 然而,webservice 不能直接访问数据库,而是使用用户创建的库查询它,并使用特定的方法来检索用户、名称等。 我通过选择 add > reference 将库包含在 webservice 项目中,并且我的 webservice 代码没有编译错误或警告。 我已经使用 svcutil.exe 和 wsutil.exe 创建了客户端库,一切正常,没有警告。 在我的客户端代码上,我收到“处理 tempuri.org.xsd 时出错”、“为 DataSet ''生成代码时出错。”和“无法将输入 xml 文件转换为 DataSet。继承的嵌套表 'Utilizador'相应的命名空间不能在不同的命名空间中有多个表”。 最后一个错误被翻译成葡萄牙语,我尽我所能将它翻译回英文,所以 YMMV...'Utilizador' 是我的数据库上的一个表名和访问数据库的库上的一个类名。 我正在使用此代码来使用 WebService:
#include "stdafx.h"
#include "WebServices.h"
#include "schemas.microsoft.com.2003.10.Serialization.xsd.h"
#include "tempuri.org.xsd.h"
#include "tempuri.org.wsdl.h"
#include <string>
#include <iostream>
#include <stdlib.h>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
unsigned int *listSize;
Utilizador **arrayUser;
HRESULT hr = ERROR_SUCCESS;
WS_ERROR* error = NULL;
WS_HEAP* heap = NULL;
WS_SERVICE_PROXY* proxy = NULL;
WS_ENDPOINT_ADDRESS address = {};
WS_STRING url= WS_STRING_VALUE(L"http://localhost:51765/Graph4Social.svc");
address.url = url;
hr = WsCreateHeap(2048, 512, NULL, 0, &heap, error);
WS_HTTP_BINDING_TEMPLATE templ = {};
//criação do proxy para o serviço
//hr = BasicHttpBinding_IGraph4WebService_CreateServiceProxy(&templ, NULL, 0, &proxy, error);
//WsCreateServiceProxy(&templ, NULL, 0, &proxy, error);
hr = BasicHttpBinding_IGraph4Social_CreateServiceProxy(&templ, NULL, 0, &proxy, error);
hr = WsCreateServiceProxy(WS_CHANNEL_TYPE_REQUEST,WS_HTTP_CHANNEL_BINDING,NULL,NULL,0,NULL,0,&proxy,error);
hr = WsOpenServiceProxy(proxy,&address,NULL,error);
hr = BasicHttpBinding_IGraph4Social_getUserList(proxy,listSize,&arrayUser,heap, NULL,0, NULL,error);
for (unsigned int i = 0; i < *listSize; i++)
cout << "ID Utilizador: " + arrayUser[i]->idUtilizador;
return 0;
}
这是接口的 WebService 代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
using TM_TDG.WithDataSets.BLL;
// NOTE: You can use the "Rename" command on the "Refactor" menu to change the interface name "IGraph4Social" in both code and config file together.
[ServiceContract]
public interface IGraph4Social
{
[OperationContract]
IList<Utilizador> getUserList();
}
这是实现接口的类的代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
using TM_TDG.WithDataSets.BLL;
// NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "Graph4Social" in code, svc and config file together.
public class Graph4Social : IGraph4Social
{
public IList<Utilizador> getUserList()
{
RedeSocial rede = RedeSocial.getRedeSocial();
IList<Utilizador> userList = rede.getUserList(true); //so queremos os utilizadores activos
return userList;
}
}
我已经用谷歌搜索了这个错误,但似乎找不到答案。我希望有人可以帮助我解决这个问题,因为我在这个问题上被困了好几天!
谢谢!
【问题讨论】:
标签: c# c++ web-services