我一直在使用 Objective-C 在 _vti_bin/copy.asmx 中定义的 CopyIntoItems Web 服务。Objective-C 的代码片段。还粘贴工作正常的.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);
请帮助我找到确切的问题。
谢谢苏德希尔