我一直在使用Objective-C使用_vti_bin / copy.asmx中定义的CopyIntoItems Web服务。 Objective-C的代码Sinppet。同时粘贴.Net代码,该代码工作正常。你能不能让我知道它在Objective-C中不起作用的原因。
Objective-C代码:
- (void)uploadDocument {
NSMutableString *str = [[NSMutableString alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"UploadDocument" ofType:@"xml"] encoding:NSUTF8StringEncoding error:nil];
NSString *path = [[NSBundle mainBundle] pathForResource:@"test2" ofType:@"txt"];
NSLog(@"path --- :%@",path);
NSString *contents = [NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:nil];
NSString *base64Str = [contents base64String];
[str replaceOccurrencesOfString:@"INP_SourceUrl" withString:path options:NSCaseInsensitiveSearch range:NSMakeRange(0, str.length)];
[str replaceOccurrencesOfString:@"INP_DestinationUrl" withString:@"http://sp2010/sites/dev2/DevLibrary/test2.txt" options:NSCaseInsensitiveSearch range:NSMakeRange(0, str.length)];
[str replaceOccurrencesOfString:@"INP_Stream" withString:base64Str options:NSCaseInsensitiveSearch range:NSMakeRange(0, str.length)];
NSLog(@" string :%@",str);
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"http://192.168.30.80/_vti_bin/copy.asmx"]];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
[request setHTTPMethod:@"POST"];
[request setValue:@"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
[request setValue:@"http://schemas.microsoft.com/sharepoint/soap/CopyIntoItems" forHTTPHeaderField:@"SOAPAction"];
[request setValue:[NSString stringWithFormat:@"%ld",(unsigned long)str.length] forHTTPHeaderField:@"Content-Length"];
[request setHTTPBody:[str dataUsingEncoding:NSUTF8StringEncoding]];
NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:request delegate:self];
NSLog(@"connection ---- :%@",connection);
}
请求XML:
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<CopyIntoItems xmlns="http://schemas.microsoft.com/sharepoint/soap/">
<SourceUrl>/private/var/root/Library/Developer/Xcode/DerivedData/SampleURLTesting-bivsvxhiwvgmsqfrbzrkffzfvpdy/Build/Products/Debug/SampleURLTesting.app/Contents/Resources/test2.txt</SourceUrl>
<DestinationUrls>
<string>http://sp2010/sites/dev2/DevLibrary/test2.txt</string>
</DestinationUrls>
<Fields>
<FieldInformation Type="Text" DisplayName="Description" InternalName="response1" Value="Ticket" />
</Fields>
<Stream>dXBsb2FkIHRlc3Q=</Stream>
</CopyIntoItems>
</soap:Body>
</soap:Envelope>
响应:
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<CopyIntoItemsResponse xmlns="http://schemas.microsoft.com/sharepoint/soap/">
<CopyIntoItemsResult>0</CopyIntoItemsResult>
<Results>
<CopyResult ErrorCode="DestinationInvalid" ErrorMessage="The Copy web service method must be called on the same domain that contains the destination url." DestinationUrl="http://sp2010/sites/dev2/DevLibrary/test2.txt" />
</Results>
</CopyIntoItemsResponse>
</soap:Body>
</soap:Envelope>
.Net代码:
string webUrl = "http://sp2010/";
WebReference.Copy copyService = new WebReference.Copy();
copyService.Url = webUrl + "/_vti_bin/copy.asmx";
copyService.Credentials = new NetworkCredential("sharepoint", "Password!", "lab");
//Declare and initiates the Copy WebService members for uploading
string sourceUrl = @"d:\test1.txt";
string[] destinationUrl = { "http://sp2010/sites/dev2/DevLibrary/test1.txt" };
WebReference.CopyResult cResult1 = new WebReference.CopyResult();
WebReference.CopyResult cResult2 = new WebReference.CopyResult();
WebReference.CopyResult[] cResultArray = { cResult1, cResult2 };
WebReference.FieldInformation fFiledInfo = new WebReference.FieldInformation();
fFiledInfo.DisplayName = "Description";
fFiledInfo.Type = WebReference.FieldType.Text;
fFiledInfo.Value = "Ticket";
WebReference.FieldInformation[] fFiledInfoArray = { fFiledInfo };
FileStream strm = new FileStream(sourceUrl, FileMode.Open, FileAccess.Read);
byte[] fileContents = new Byte[strm.Length];
byte[] r = new Byte[strm.Length];
int ia = strm.Read(fileContents, 0, Convert.ToInt32(strm.Length));
strm.Close();
uint copyresult = copyService.CopyIntoItems(sourceUrl, destinationUrl, fFiledInfoArray, fileContents, out cResultArray);
请帮我找出确切的问题。
由于 Sudheer
答案 0 :(得分:0)
确保在“Sharepoint管理中心应用程序管理”中将http://sp2010
配置为有效的Sharepoint映射。配置备用访问映射
您没有它,但如果URL具有端口号,则还应在SP AAM中配置它。
重要!请勿在服务端点URL中使用IP地址。
这应该工作。我从Java :)做同样的事情。
祝好运,
鲍里斯